Robot Framework Interface Test (3)--http request post

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.