[英]python requests.post data without value don't work
how can i post only key of form data to a server like the site itself?如何仅将表单数据的密钥发布到站点本身这样的服务器?
In [1]: from requests import Request
In [2]: req = Request('POST', 'http://www.google.com', data={'json':''}).prepare()
In [3]: req.headers, req.body
Out[3]:
({'Content-Length': '5', 'Content-Type': 'application/x-www-form-urlencoded'},
'json=')
In [4]: req = Request('POST', 'http://www.google.com', data={'json':None}).prepare()
In [5]: req.headers, req.body
Out[5]: ({'Content-Type': 'application/x-www-form-urlencoded'}, '')
the 'Content-Length' can't equal length of key, like 4. and, how can i make the body equal 'json' ? 'Content-Length' 不能等于键的长度,如 4. 并且,我怎样才能使 body 等于 'json' ? thx all
谢谢大家
From the documentation :从文档:
There are times that you may want to send data that is not form-encoded.
有时您可能想要发送非表单编码的数据。 If you pass in a
string
instead of adict
, that data will be posted directly.如果您传入
string
而不是dict
,则该数据将直接发布。
In your case, that means doing this:在你的情况下,这意味着这样做:
req = Request('POST', 'http://www.google.com', data='json').prepare()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.