POST request returning null values

Question:

I’m trying to make some POST requests to a website and, while I get 200 responses every time I do so, the values of said responses are all either null or 0’s.

I’ve tried using all the headers visible when inspecting the website, just a combination of them, insertint cookies, etc. and nothing seems to solve the issue. I even tried making the request via Insomnia but I always get the same output. Any idea why?

This is the website: https://prestamos.moneygo.es/creditomoneygo/movilidad/index.htm?canal=WEB_MONEYGO&utm_source=Xfera&utm_medium=Web&utm_campaign=pmxfera_clientesxfera

And here some of the code I’ve tried:

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)

EDIT

I included the cookies as the correct answer suggested and it worked.

Since I didn’t want the cookies to be hardcoded, this is what my final solution ended up looking like:

r = requests.get(#URL to the website)
cookies = r.cookies
r = requests.post(#URL, headers=headers, data=payload, cookies=cookies)

Also, I had to remove the "Cookie" key-value pair from the payload dictionary!

Asked By: martifapa

||

Answers:

It seems you needed the cookies, the following request returns a fully populated JSON:

import requests

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,pl;q=0.6,es;q=0.5,nl;q=0.4',
    'Connection': 'keep-alive',
    'Content-Length': '68',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'CREDITOCETELEMID=1Or6sAgWJhqhxdw7YPLyuln7Y2ByReU9Ny41LJ77nCkJ1k4Ke822!1695828990; cookieKona=3836044042.56751.0000; at_check=true; mbox=session#1f789849651d4030ac0d0ad97c6a70b7#1679244946|PC#1f789849651d4030ac0d0ad97c6a70b7.37_0#1742487886',
    'Host': 'prestamos.moneygo.es',
    'Origin': 'https://prestamos.moneygo.es',
    'Referer': 'https://prestamos.moneygo.es/creditomoneygo/movilidad/index.htm?canal=WEB_MONEYGO',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    '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',
    'sec-ch-ua': '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': 'Windows'
}

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)
Answered By: R_D