The HTTP request is more of a POST request, and we can:
View Description:
Many websites need to add the head information when logging in, namely headers, this information can obtain--fiddler by grasping the package tool, a lightweight grasping the bag tool, the great God used all say well ~
Here to simulate the blog Park login, first in the first part of the simulation login operation, the background open fiddler Crawl login information:
Once this information is available, you can write the headers information in your code, and the information you need to log in:
#coding: Utf-8import requestsdef 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 ': ' um_distinctid=15ad2746631137-0753f3fbde32fd-591e3916-100200-15ad27466332a0; __gads=id=b4b937f355218cb8:t=1494253102:s=alni_ma7okjsqjtxdlalyh-yb4dlk0kouw; _ga=ga1.2.1665904319.1495250472; _gid=ga1.2.1373367502.1495252278; Serverid=9b2e527de1fc6430919cfb3051ec3e6c|1495252557|1495250466 ',
' Connection ': ' Keep-alive '}
Payload = {#这是我的用户名和密码 (changed to wrong)
"INPUT1": ' kceho2gs9jgtynvxvo03thsyygiyg/g618kdruk= ',
' Input2 ': ' no1f0itxbsuem+vy4jlr7lkseqn3oktwmdsbi= ',
' Remember ': True}
r = Requests.post (URL, json=payload, headers=headers, Verify=false)
Return R.json ()
?
Call this function:
Print Post_info ()
You can see the return login success prompt:
Code Description:
1. As this is an HTTPS request, a direct send request will report an error: Sslerror: [Ssl:certificate_verify_failed]certificate VERIFY FAILED, you can add a parameter: Verify=false, Indicates that validation of the SSL certificate is ignored
2. The final result is JSON format, which can return JSON data directly with R.json: {u ' success ': True}
Here we know the way the post is requested, and then we can achieve our ultimate goal-the interface test.
Public search "automated test Practice" or scan the QR code below to add attention ~ ~ ~
Robot Framework Interface Test (3)--http request post