我应该寄这个:
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 body被设置为
ON
;使用data
参数:params
参数用于URL查询参数,通过使用字典,您要求{?ON=
被添加到URL中。在参见^{} manpage :
以及^{} API :
requests.post
方法中的params
参数用于向URL添加GET参数。所以你在做这样的事情:您应该改为使用
^{pr2}$data
参数。在此外,如果给data参数一个字典,它将以“application/x-www-form-urlencoded”的形式发送有效负载。在curl命令中,发送原始字符串作为有效负载。所以我改变了你的例子。在
相关问题 更多 >
编程相关推荐