我试图发送的正文:
update_request={
"id": "f07de0a44c2911ea8fb2bc764e10b970",
"user": {
"user": "3491574055045",
"timestamp": "1640049459",
"signature": "YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D",
"code": "test"
}
}
这是我现在的代码:
url = "https://api.ordergroove.com/customer/update_customer"
headers = {
'content-type': 'application/json'
}
body = """
update_request={{
"id": "f07de0a44c2911ea8fb2bc764e10b970",
"user": {
"timestamp": "1640049459",
"signature": "YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D",
"code": "test"
}
}}
"""
#Send and print response
response = requests.post(url, data=body, headers=headers)
如果我在 Postman 中运行它,它工作得很好: Postman screenshot
最佳答案
import requests
url = "https://46463d29-e52d-4bb9-bdda-68f0dfd7d06d.mock.pstmn.io/test"
payload = " update_request={{\r\n \"id\": \"f07de0a44c2911ea8fb2bc764e10b970\",\r\n \"user\": {\r\n \"timestamp\": \"1640049459\",\r\n \"signature\": \"YQvl1dWkN6MrHQ8xGwEQndVo2QdPSzc6EqLJslzNjy4%3D\",\r\n \"code\": \"test\"\r\n }\r\n }}"
headers = {
'Content-Type': 'text/plain'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
您可以从 postman 本身生成代码
关于python - 如何在Python POST请求中发送原始数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70430339/