You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

POST请求始终返回null或0值的问题排查及解决

POST请求返回200但结果始终为null/0的问题及解决方法

问题详情

我尝试向目标网站发送POST请求,每次都能得到200的成功响应,但返回值始终是null或0。我试过使用浏览器抓取的所有请求头、组合不同请求头、手动添加cookies等操作,甚至用Insomnia工具发送请求,结果都完全一致。

目标网站地址:https://prestamos.moneygo.es/creditomoneygo/movilidad/index.htm?canal=WEB_MONEYGO&utm_source=Xfera&utm_medium=Web&utm_campaign=pmxfera_clientesxfera

尝试的代码

import requests

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,ca;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Length': '68',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Host': 'prestamos.moneygo.es',
    'Origin': 'https://prestamos.moneygo.es',
    'Pragma': 'no-cache',
    'Referer': 'https://prestamos.moneygo.es/creditomoneygo/movilidad/index.htm?canal=WEB_MONEYGO&utm_source=Xfera&utm_medium=Web&utm_campaign=pmxfera_clientesxfera',
    'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
}

payload = {
    'numCuotas': 60,
    'importe': 10000,
    'material': 501,
    'producto': 'MD',
    'esClienteYoigo': 0,
}

r = requests.post('https://prestamos.moneygo.es/creditomoneygo/movilidad/rest/simular.htm', headers=headers, data=payload)

解决方法

添加cookies后问题得到解决。为避免硬编码cookies,最终方案是先向网站发送GET请求获取有效cookies,再携带该cookies发送POST请求,同时需确保payload中没有Cookie相关键值对。代码示例如下:

# 先发送GET请求获取cookies
r = requests.get('https://prestamos.moneygo.es/creditomoneygo/movilidad/index.htm?canal=WEB_MONEYGO&utm_source=Xfera&utm_medium=Web&utm_campaign=pmxfera_clientesxfera')
cookies = r.cookies

# 携带获取到的cookies发送POST请求
r = requests.post('https://prestamos.moneygo.es/creditomoneygo/movilidad/rest/simular.htm', headers=headers, data=payload, cookies=cookies)

内容的提问来源于stack exchange,提问作者martifapa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 21:52:32