python接口测试(requests库)-1

python接口测试(requests库)-1
requests是python的http库
参考:https://blog.youkuaiyun.com/qq_31524409/article/details/80984729
https://www.cnblogs.com/qiaoxin/articles/7928290.html

接口测试的步骤:
1>获取接口的url地址
2>查看接口的发送方式
3>添加请求头、请求体
4>查看返回结果,校验返回结果是否正确

#urllib的get请求

import urllib.request

url=‘http://www.baidu.com

response=urllib.request.Request(url=url)

html=urllib.request.urlopen(response)

print(html.getcode())

print(html.headers)

#urllib的post代码
import urllib.request

import urllib.parse

url=‘http://www.tuling123.com/openapi/api

data={“key”: “your”, “info”: ‘你好’}

data=urllib.parse.urlencode(data).encode(‘utf-8’)

re=urllib.request.Request(url,data)

html=urllib.request.urlopen(re)

print(html.getcode(),html.msg)

print(html.read())

#request库的get请求
import requests

r = requests.get(‘https://www.baidu.com’)

print(r.headers)

#requests库的post请求
import requests
payload = {‘key1’: ‘value1’, ‘key2’: ‘value2’}
r = requests.post(“http://httpbin.org/post”, data=payload)
print(r.text)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值