如何使用特定参数发出post请求

2024-09-29 21:50:50 发布

您现在位置:Python中文网/ 问答频道 /正文

是否可以使用python请求从这个site访问原始数据

在网络选项卡中,我找到了getAllDeclaration项,该项具有POST方法并指定请求有效负载参数

到目前为止,我已经尝试过:

url = "https://cab.vkksu.gov.ua/rest/qa2_resultLatest/"
payload = {"PIB": "Іванов Іван Іванович", "docTypeID": "3000000768001", "yearString": "2018", "pageNum": 0}
# `docTypeID` I got from https://cab.vkksu.gov.ua/rest/qa2_interview/getInterviewType"
requests.post(url, payload)
# results in 400 response code

Tags: https网络resturl原始数据site选项卡gov
2条回答

试试这个:

import json
url = "https://cab.vkksu.gov.ua/rest/qa2_resultLatest/"
payload = {"PIB": "Іванов Іван Іванович", "docTypeID": "3000000768001", "yearString": "2018", "pageNum": 0}
header = "application/json"
mydata = json.dumps(payload)
# `docTypeID` I got from https://cab.vkksu.gov.ua/rest/qa2_interview/getInterviewType"
resp = requests.post(url, mydata,header)
print(resp.content)

试试下面的代码,你肯定把url部分搞糟了

import requests

url = "https://cab.vkksu.gov.ua/rest/qa2_resultLatest/getAllDeclaration" 
data = {
    "PIB": "Іванов Іван Іванович", 
    "docTypeID": "3000000768001", 
    "yearString": "2018", 
    "pageNum": 0
}
response = requests.post(url, json=data)

print(response.json())

相关问题 更多 >

    热门问题