cdzjf 发表于 2021-3-24 20:36:15

requests请求中的body参数的问题

抓包的参数,发现最下面有一行,看表单下面是个body参数,有3个api_s,api_m,params
params参数解码出来是个字典,我请求不是未知错误就是返回请求的参数不正确,这个到底应该如何请求呢?

我的请求
res = requests.post(url=url, headers=head, data=json.dumps(body)).text
改成
res = requests.post(url=url, headers=head, data=(body)).text
把body中的params用编码的方式传入,都是错误

qiuyouzhi 发表于 2021-3-24 20:55:01

你的body是啥..

suchocolate 发表于 2021-3-24 20:58:02

requests的data参数可以直接用字典,不用专门转成json。

kogawananari 发表于 2021-3-24 22:05:43

requests默认使用application/x-www-form-urlencoded对POST数据编码。如果要传递JSON数据,直接传入json参数

requests.post(url=url, headers=head, json=body)

cdzjf 发表于 2021-3-25 14:51:33

本帖最后由 cdzjf 于 2021-3-25 16:46 编辑

qiuyouzhi 发表于 2021-3-24 20:55
你的body是啥..

抓包的:
sevData=%7B%22source%22%3A2%2C%22sharePin%22%3A%22%22%2C%22userId%22%3A%22C2E8390B7965ECF865AB60076D2F89CE%22%2C%22userToken%22%3A%22CFB3F9DC8435645869ED751D909FE77C%22%2C%22shareType%22%3A1%2C%22channel%22%3A%22%22%22riskDeviceParam%22%3A%22%7B%5C%22eid%5C%22%3A%5C%22PXAXFRJARCJIU6WL3PNRDOE4NFK77RIICWP2WHHSN7TCEOBP433N45AVCLOEEEAVZMN5W275109884fa007a57218afcc47fe8a%5C%22%2C%5C%22sdkToken%5C%22%3A%5C%22SM6JH6IBYMZ2P2HA5RZXKRFREKUUYLEZ7NA4GCCZMXFSZXY4FTKTONJNZLVLPFPBEGWHHUTSA4C3C53KOBA6CA2OLRIMA01234567%5C%22%2C%5C%22token%5C%22%3A%5C%22GXIZFHWZ6OZENY7BAGBAYC26SK2Y76VJ7CXJ6LQVNE4EIYQUGPKDC5ALJLZ2H5Z7ES%5C%22%2C%5C%22jstub%5C%22%3A%5C%22IQXJGZJONMK3ECS7Y5J3PU3C3UJDYY3NABEISIKOFLPRZLUC5XZIKLFJPUNBI%5C%22%2C%5C%22appType%5C%22%3A4%7D%22%7D
解码后
sevData={"source":2,"sharePin":"","userId":"C2E8390B7965ECF865AB60076D2F89CE","userToken":"CFB3F9DC8435645869ED751D909FE77C","shareType":1,"channel":"","riskDeviceParam":"{\"eid\":\"PXAXFRJARCJIU6WL3PNRDOE4NFK77RIICBP433N45AVCLOEEEUVQP6VS75WI\",\"fp\":\"bd275109884fa007a57218afcc47fe8a\",\"sdkToken\":\"XRAKTMKY6WSM6JH6IBYMZ2P2HA5RZXKRFREKUUYLEZ7NA4GCCZMXFSZXY4FTKTONJNZLVLPFUTSA4C3C53KOBA6CA2OLRIMA01234567\",\"token\":\"GXIZFHWZ6OZENKY3TUIX44OFY7BAGBAYC26SK2Y76VJ7CXJ6LQVNEJLZ2H5Z7ES\",\"jstub\":\"IQXJGZJONMK3ECS7Y5J3PU3C3UJDYY3NABEISIKOFLBDQQW2VV
我这样的怎么做呢?

requests.post(url=url,headers=headers,data=data)

用解码后说服务器繁忙,显然是参数不正确,换成没有解码的就没问题
页: [1]
查看完整版本: requests请求中的body参数的问题