python中request中的params,data,json参数含义全解
我们先来看下CTFLEARN中的114 challenge:POST Practice
This website requires authentication, via POST. However, it seems as if someone has defaced our site.Maybe there is still some way to authenticate? http://165.227.106.113/post.php
查看http://165.227.106.113/post.php页面源码,即可发现username: admin | password: 71urlkufpsdnlkadsf,简单来说,此题需要我们向http://165.227.106.113/post.php,发送post请求,将username和password参数提交,即可得到flag。
import requests userinfo = { "username": "admin", "password": "71urlkufpsdnlkadsf" } # 方法1,使用data发送,此题的正确答案 response = requests.post("http://165.227.106.113/post.php", data=userinfo) print(response.text) # 方法2: 使用json # response = requests.post("http://165.227.106.113/post.php", json=userinfo) # print(response.text) # 方法3:直接在url上加参数 # response = requests.post("http://165.227.106.113/post.php?username=admin&password=71urlkufpsdnlkadsf") # print(response.text) # 方法4: 使用params参数,和方法3等同 # response = requests.post("http://165.227.106.113/post.php", params="username=admin&password=71urlkufpsdnlkadsf") # print(response.text)
python中的四种方法有何区别呢?笔者guggle(csdn远古某人)发现,这4种请求方式的区别在于:请求的url,请求header中Content-Type,请求的body不同。
方法1:使用data
url: http://165.227.106.113/post.php
header中的Content-Type:application/x-www-form-urlencoded
body:username=admin&password=71urlkufpsdnlkadsf
方法2:使用json
url: http://165.227.106.113/post.php
header中的Content-Type:application/json
body:{“username”: “admin”, “password”: “71urlkufpsdnlkadsf”}
方法3和方法4:直接在url上加参数和使用params
url: http://165.227.106.113/post.php?username=admin&password=71urlkufpsdnlkadsf
header中的Content-Type:没有声明
body:none
————————————————
版权声明:本文为CSDN博主「远古某人」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/guggle15/article/details/120362917