请求 post 个字典格式错误的数据
Requests post data with dictionary format error
将发送到服务器的表单数据如下所示:
我没有把它 post 正确地发送到服务器。我已经试过了:
payload = {
"ad_id": ad_id,
"ad_type": "1",
"csrf_token": crsf_token,
"messages": [{'content': 'message to server', 'message_type': 'text'}],
"user_id": "9020446"
}
#
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Type": "application/json",
"Origin": "https://www.wg-gesucht.de",
"Referer": f"https://www.wg-gesucht.de/nachricht-senden.html?message_ad_id={ad_id}"
}
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', payload, headers=headers)
我也试过了:
"messages": ['message to server']
但我总是收到 401 错误。
如果有人能帮助我就太好了。
此致!
您可以在 python
中使用 "requests" 库
import requests
payload = {
"ad_id": ad_id,
"ad_type": "1",
"csrf_token": crsf_token,
"messages": [{'content': 'message to server', 'message_type': 'text'}],
"user_id": "9020446"
}
#
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Type": "application/json",
"Origin": "https://www.wg-gesucht.de",
"Referer": f"https://www.wg-gesucht.de/nachricht-senden.html?message_ad_id={ad_id}"
}
res = requests.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', data=payload, headers=headers)
我刚刚将 posttype 更改为 "json",这为我修复了错误:
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', json=payload, headers=headers)
还是谢谢大家的帮助。
将发送到服务器的表单数据如下所示:
我没有把它 post 正确地发送到服务器。我已经试过了:
payload = {
"ad_id": ad_id,
"ad_type": "1",
"csrf_token": crsf_token,
"messages": [{'content': 'message to server', 'message_type': 'text'}],
"user_id": "9020446"
}
#
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Type": "application/json",
"Origin": "https://www.wg-gesucht.de",
"Referer": f"https://www.wg-gesucht.de/nachricht-senden.html?message_ad_id={ad_id}"
}
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', payload, headers=headers)
我也试过了:
"messages": ['message to server']
但我总是收到 401 错误。
如果有人能帮助我就太好了。
此致!
您可以在 python
中使用 "requests" 库import requests
payload = {
"ad_id": ad_id,
"ad_type": "1",
"csrf_token": crsf_token,
"messages": [{'content': 'message to server', 'message_type': 'text'}],
"user_id": "9020446"
}
#
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Type": "application/json",
"Origin": "https://www.wg-gesucht.de",
"Referer": f"https://www.wg-gesucht.de/nachricht-senden.html?message_ad_id={ad_id}"
}
res = requests.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', data=payload, headers=headers)
我刚刚将 posttype 更改为 "json",这为我修复了错误:
res = browser.post('https://www.wg-gesucht.de/ajax/api/Smp/api.php?action=conversations', json=payload, headers=headers)
还是谢谢大家的帮助。