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