我应该发送此:
curl --header "Content-Type: text/plain" --request POST --data "ON" example.com/rest/items/z12
相反,我发送的是:
import requests
headers = {"Content-Type": "text/plain"}
url = 'http://example.com/rest/items/z12'
_dict = {"ON": ""}
res = requests.post(url, auth=('demo', 'demo'), params=_dict, headers=headers)
我收到错误400(错误请求?)
我究竟做错了什么?
该POST体被设置为ON
; 使用data
参数:
import requests
headers = {"Content-Type": "text/plain"}
url = 'http://example.com/rest/items/z12'
res = requests.post(url, auth=('demo', 'demo'), data="ON", headers=headers)
该params
参数用于URL查询参数,并通过使用字典要求requests
将其编码为表单编码。因此?ON=
已添加到URL。
参见手册curl
页:
(HTTP)将POST请求中的指定数据发送到HTTP服务器,就像浏览器在用户填写HTML表单并按下Submit按钮时所做的一样。
数据–(可选)要在的正文中发送的字典,字节或类似文件的对象
Request
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句