Robot Framework Interface Test (2)--http request get

Source: Internet
Author: User

Originally intended to send the HTTP request get and Post methods are introduced, the results found a bit long, text editing also become confusing, so here first introduce the Get method, the next time post. In fact, these methods you can see the source of the introduction only need to enter in the code:

Import requests

Help (requests)

You can see an explanation with the example:

I don't feel the need to write anymore ... O (∩_∩) o haha ~, cough, let's get started ha

The last time we finished splicing the message, now we are going to complete the second step of RF interface testing: Send the request.

Python sends the HTTP request module mainly has requests, urllib, URLLIB2, here we introduce three inside the simplest requests module.

Installing the Requests module: PIP Install requests

1. Get

The URL can be accessed directly using the Get method after importing requests:

#coding: utf-8import requestsclass SendingInfo(object):      ROBOT_LIBRARY_SCOPE = ‘GLOBAL‘
ROBOT_LIBRARY_VERSION = ‘0.1‘
def __init__(self):
pass def sending_info(self):
rs = requests.get(‘https://www.baidu.com‘)
#打印状态码
print rs.status_code
#打印返回html
print rs.content
#打印头文件信息
print rs.headers
#打印cookies
print rs.cookies
?

After instantiating the class, the calling function can see the printed return:

Return information you can see more information in addition to the above print:

Rs.url--Get URL

Rs.json ()--JSON decoder built into requests

Rs.text--The response body of a string, is automatically decoded according to the character encoding of the response header. Rs.text may be garbled compared to r.content.

Rs.encoding--Encoding format

Public search "automated test Practice" or scan the QR code below to add attention ~ ~ ~

Robot Framework Interface Test (2)--http request get

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.