2 Enables you to quickly get response headers and senders

Keywords: JSON encoding Windows Javascript

Today we're going to use two quick ways to get response headers and send headers.

1. Get Request Header

To get the request header, you need to use the package capture tool, which is currently more common than fiddler.You can search and download in Baidu.First let's turn on fiddler


You'll find that on the left side there's an increasing number of requests from our computers



Click here to select Remove all to empty all requests.Now let's take the blog Park login as an example, first look at the response header, then the request header:

Enter the blog park, click on the login button in the upper right corner (note that you have opened fiddler) to login. Now the blog park needs to stitch a picture to login. Then we empty the fiddler send list before stitching pictures, and then go to stitch pictures to complete the login operation. After login, you can see:



We see this login interface in fiddler, get the address of the interface, continue to look at the interface in fiddler, select Inspectors on the right and Raw on the next line:


After selecting, we see things like User-Agent, Accept, Accept-Encoding, Cookie, and so on. That's what we're looking for ~~

2. Response Header

Let's write a script or blog Park login interface:

#coding: utf-8

import requests

def post_info(): url = "https://passport.cnblogs.com/user/signin" headers = { "User-Agent": 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Accept-Encoding': 'gzip, deflate, sdch', 'Accept-Language': 'zh-CN,zh;q=0.8', 'Content-Type': 'application/json; charset=UTF-8', 'Content-Length': '385', 'X-Requested-With': 'XMLHttpRequest', 'Cookie': 'AspxAutoDete5002db93f6|1509713553|1509713284', 'Connection': 'keep-alive'} payload = { #This is my username and password (changed incorrectly) "input1": 'Cvlwp32tCIKCcvEz653QkK2+23JNkTjpeKveMU/k=', 'input2': 'QIkqWfSBWp0UafzxeiaxLE0MwW8cOM64I9JTUjP9/I+5yxAg=', 'remember': True} r = requests.post(url, json=payload, headers=headers, verify=False) return r.headersprint post_info() 

The Cookie of the code above is the very long string inside the duplicated fiddler. input1 and input2 are also inside the duplicated fiddler, and then run the code.This code was not logged in successfully, yes, it was not logged in successfully. If you want to know if it is successful, you can replace the second-to-last line of return r.headers with r.json(), and you can see it.Although the login was unsuccessful, we can get the response header based on the return of the interface. Yes, the last r.headers we get from this code is the response header. Take a look:

{'Set-Cookie': 'SERVERID=227b0876674;Path=/', 'X-AspNet-Version': '4.0.30319', 'Transfer-Encoding': 'chunked', 'X-AspNetMvc-Version': '5.2', 'X-Powered-By': 'ASP.NET', 'Connection': 'keep-alive', 'X-UA-Compatible': 'IE=10', 'Cache-Control': 'private', 'Date': 'Fri, 03 Nov 2017 13:03:53 GMT', 'Content-Type': 'application/json; charset=utf-8'} 

If you have experience in software testing, interface testing, automated testing, and interviews.Interested in software testing and communication: 1085991341, there will be peer technical exchanges.
Tip: The code above can be pulled right

r.headers is the way to get the response header.

In addition, I would like to tell you about the common methods:

Note that r here refers to the return value of the post or get method


As long as you hit r in pycharm, the available methods will pop up automatically. The pictures above have a brief description of the corresponding methods, which you can refer to.
The above content is expected to be helpful to you. Those who have been helped are welcome to comment and comment.

Posted by d3vilr3d on Wed, 27 May 2020 18:09:37 -0700