04-07 接口请求构造

Posted Leofighting

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了04-07 接口请求构造相关的知识,希望对你有一定的参考价值。

get query 请求

params_query = {
"key1": "value1",
"key2": "value2"
}

r = requests.get(url, params=params_query)

form 请求

params_form = {
"key1": "value1",
"key2": "value2"
}

r = requests.post(url, data=params_form)

文件上传

files = {
"file": open("file_path", "rb")
}

r = requests.post(url, files=files)

header

headers = {
"user-agent": "agent"
}

r = requests.get(url, headers=headers)

cookie

cookies = {
"cookies": "value"
}

r = requests.get(url, cookies=cookies)

以上是关于04-07 接口请求构造的主要内容,如果未能解决你的问题,请参考以下文章