pytest

HTTP

HTTP是一个协议(服务器传输超文本到浏览器的传送协议)是基于TCP/IP通信协议来传递数据(HTML文件,图片文件,查询结果等)

http资源

http请求方式

http状态码

Requests模块

pycharm创建项目并进行接口请求

下载requests,直接导包下载或者在终端使用pip install requests

requests官网

https://requests.readthedocs.io/en/latest/

get请求

编写请求代码:

import requests

r = requests.get("https://api.github.com/events")
print(r.status_code) #接口状态返回码
print(r.json()) #接口返回的json
print(r.text) #接口返回的文本

运行结果:

请求中携带参数代码:

import requests

params = {
    "shouji": "13456766448",
    "appkey": "0c818521d38759e1"
}

r = requests.get(url="http://api.binstd.com/shouji/query", params=params)
print(r.status_code)
print(r.json())

运行结果:

post请求

params形式:

import requests

params = {
    "shouji": "13456766448",
    "appkey": "0c818521d38759e1"
}

r = requests.post(url="http://api.binstd.com/shouji/query", params=params)
print(r.status_code)
print(r.json())

运行结果:

json形式:

import requests

json_data = {
    "title": "foo",
    "body": "bar",
    "userId": 1
}

r = requests.post(url="http://jsonplaceholder.typicode.com/posts", json=json_data)
print(r.status_code)
print(r.json())

运行结果:

data形式:

import requests

data = {
    "text":"hello"
}

r = requests.post(url="http://dict.youdao.com/keyword/key",data=data)
print(r.status_code)
print(r.json())

运行结果:

requests加入headers:

Pytest

在终端安装pytest

pip install pytest
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值