1. library requests the transmission request, fiddler not capture packets; the same browser request url, can capture packets
- Proxies add parameters in the request parameters, as follows:
-
= Proxies { ' HTTP ' : ' http://127.0.0.1:8888 ' , ' HTTPS ' : ' http://127.0.0.1:8888 ' , } Requests your request methods (. ' your request ' , Data = your payload, proxies = proxies)
proxies is a dictionary, which is the value fiddler proxy and port
2. Print get / post returns the requested value
-
= requests.get obj ( " request address " , Data = { " Request parameter " }) Print (obj.text) Print (obj.json ())
3. Return value print beautiful
4. The method of parameters corresponding to the request
parameter | Explanation | get | post | put | delete |
url | Have | Have | Have | Have | |
params | If you pass a field. Automatic encoded form; String | Have | |||
data | If a string is passed, according to the cell format released directly out | Have | Have | Have | |
json | If the dictionary is passed automatically json encoded as a string; If a string is passed, based on the format of the original double quotes sent out; |
Have | |||
headers | Passed a dictionary format | Have | Have | Have | Have |
cookies | Have | Have | Have | Have |
generally:
The get request parameters params, passing the dictionary;
JSON post request parameters;
6. What is a request to return text, what is the result of a request to return json?
baidu = requests.get("https://www.baidu.com") print("baidu:",baidu.json()) #报错 print("baidu:",baidu.text) #不报错
- View response hesders value of the content-type.
7. request headers parameter, what?
- Using web calls, see parameter F12 in the browser requests headers in
- Or with a postman calls, check the parameters of Headers