使用firefox插件“ HttpFox”,我得到的POST请求如下所示:
{'json':'{"command":"SEARCH","data":{"someData":"someValue","otherData":"otherData"}}'}
现在,我需要发送一个使用python构建的http请求,以获取与通过浏览器获取的数据相同的数据。看到代码:
headers = {'Content-type': 'application/json; charset=utf-8'}
payload = ?
req = requests.post(url, data=json.dumps(payload), headers = headers)
我的问题是:我不确定如何构建有效负载。它也应该是一个字典,但是由于HttpFox附带的POST类型而使我感到困惑。主词典中有两个词典。
我该如何处理?感谢任何帮助。
好的,我找到了解决方案:
有必要建立一个像这样的字典:
valueString = """{"command":"SEARCH","data":{"someData":"someValue","otherData":"otherData"}}"""
/// the """ ensures that the whole text between """ is handled as a string.
payload = {'json': valueString}
键“ json”需要一个字符串。在这种情况下,字符串看起来像字典。
而已。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句