我正在尝试调用一个在 Postman 上运行的发布请求,但我的代码返回 400。以下是我的尝试:
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth?
accountid=342&password=3534"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, headers=headers)
print (rsp.status_code)
和
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth"
Body1 = {
"accountid": "342",
"password": "3534"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, json=Body1, headers=headers)
print (rsp.status_code)
和
params = {'accountid': '342', 'password': '3534'}
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth?
accountid=342&password=3534"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
rsp = requests.post(url, headers=headers, params = params)
print (rsp.status_code)
最佳答案
params = {'accountid': '342', 'password': '3534'}
url = "http://192.168.9.194:7780/xtv-ws-client/api/login/auth"
rsp = requests.post(url, data=params)
print (rsp.status_code)
关于python - POST 请求使用 pydev Eclipse 获取 400 错误代码,但在 Postman 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51088698/