[英]How to send POST request with custom data
我正在嘗試從服務器獲取響應並將此響應保存到 json 文件。 問題是我無法請求自定義數據,即使我嘗試更改一些參數,也沒有任何效果。
這是我的代碼:
import requests
cookies = {
'e44cd683218d4334fdd9a0a70f77718b': '70e21e527a02d22cbd7c74f423b00666',
'cookieconsent_status': 'allow',
'_gcl_au': '1.1.1044858313.1660121622',
}
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
# 'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://global-standard.org/find-suppliers-shops-and-inputs/certified-suppliers/database/search_results?total=9461',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest',
'Origin': 'https://global-standard.org',
'Connection': 'keep-alive',
# Requests sorts cookies= alphabetically
# 'Cookie': 'e44cd683218d4334fdd9a0a70f77718b=70e21e527a02d22cbd7c74f423b00666; cookieconsent_status=allow; _gcl_au=1.1.1044858313.1660121622',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
}
params = {
'task': 'xforms_get_items',
'context': 'search',
}
data = {
'condition': '',
'order': '',
'limit': '10',
'page': '0',
'pageChanged': 'false',
}
response = requests.post('https://global-standard.org/find-suppliers-shops-and-inputs/certified-suppliers/database/search', params=params, cookies=cookies, headers=headers, data=data)
假設我想發送帶有下一個數據的 POST 請求
data = {
'condition': '',
'order': '',
'limit': '50',
'page': '3',
'pageChanged': 'false',
}
我相信 'limit' 和 'page' 值是您想要更改並作為有效負載傳遞的值,所以只需給它一些變量 line 'a' 或 'b' 並傳遞 'a' 或 'b' 代替 '50 ' 和 '3' 就是這樣。
沒關系,他們提供了從列表中請求所有數據的選項!
這樣我的代碼才能工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.