POST请求使用pydev Eclipse获得400错误代码,但使用Postman

时间:2018-06-28 17:39:33

标签: python eclipse api request postman

我正在尝试调用一个在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)

这是我的邮递员要求: enter image description here

1 个答案:

答案 0 :(得分:1)

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)