我正在努力使用python POST
做一个合适的requests
。我正在使用mitmproxy
分析一个网站,发送的参数列为
_cmc.workload: {
"Requests": [
{
"Service": "CourseOfSalesGet1",
"TId": 11,
"Request": {
"Page": 1,
"Stock": "BHP"
},
"DeferExecution": false,
"SkipCache": false
},
{
"Service": "QuoteGet1",
"TId": 12,
"Request": {
"Stock": "BHP"
},
"DeferExecution": false,
"SkipCache": false
}
]
}
我将其转换为:
params={
'_cmc.workload': {"Requests":[{"Service":"CourseOfSalesGet1","TId":"11","Request":{"Page":"1","Stock":"BHP"},"DeferExecution":"false","SkipCache":"false"},{"Service":"QuoteGet1","TId":"12","Request":{"Stock":"BHP"},"DeferExecution":"false","SkipCache":"false"}]}
}
mitmproxy的标头:
content-type: application/x-www-form-urlencoded; charset=UTF-8
accept: application/json, text/javascript, */*; q=0.01
x-requested-with: XMLHttpRequest
accept-language: en-au
accept-encoding: br, gzip, deflate
我将标头转换为此:
headers={
'content-type':'application/x-www-form-urlencoded',
'accept':'application/json, text/javascript, */*',
'x-requested-with':'XMLHttpRequest',
'accept-language':'en-au',
'accept-encoding':'br, gzip, deflate'
}
我的POST
的格式为
requests.session.post('https://www.example.com', headers=headers,data=params)
我正在使用一个会话,因为该站点需要登录,并且我已经很好地处理了。只是无法弄清楚如何正确发送帖子数据,因为该站点的回复说我发送了一个空请求。
尽管在mitmproxy
上回放时,该帖子仍然可以正常工作。我该如何正确发送此邮件?
答案 0 :(得分:0)
好吧,只需将引号添加到内部字典中即可,如图所示:
params={
'_cmc.workload': '{"Requests":[{"Service":"CourseOfSalesGet1","TId":"11","Request":{"Page":"1","Stock":"BHP"},"DeferExecution":"false","SkipCache":"false"},{"Service":"QuoteGet1","TId":"12","Request":{"Stock":"BHP"},"DeferExecution":"false","SkipCache":"false"}]}'
}