-1
I used the Curl of the post office site to turn into a nodejs request (I used this site to convert Curl into js code-> https://curl.trillworks.com/)
var request = require('request');
var headers = {
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Origin': 'https://www2.correios.com.br',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
'Sec-Fetch-Dest': 'document',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Referer': 'https://www2.correios.com.br/sistemas/rastreamento/default.cfm',
'Accept-Language': 'en-US,en;q=0.9,pt;q=0.8',
'Cookie': '_ga=GA1.3.1385639005.1586277520; CFID=31280658; CFTOKEN=1c6b8efc2c6ad4c1-ED1DB9DE-FA31-5E5A-CF1D02F2BF2CB440; CFGLOBALS=urltoken%3DCFID%23%3D78315721%26CFTOKEN%23%3De66c3a82c674de4%2D861C7DF3%2DDAB6%2DE583%2DD427EAE724F26F87%26jsessionid%23%3D6CE45E28E642304EA69CD721D3293F2D%2Ecfusion01%23lastvisit%3D%7Bts%20%272020%2D04%2D23%2009%3A29%3A29%27%7D%23hitcount%3D5%23timecreated%3D%7Bts%20%272020%2D04%2D15%2010%3A52%3A13%27%7D%23cftoken%3D1c6b8efc2c6ad4c1%2DED1DB9DE%2DFA31%2D5E5A%2DCF1D02F2BF2CB440%23cfid%3D31280658%23; ssvbr0331_www2sro=sac2844SRO; _gid=GA1.3.940270031.1587816025; ssvbr0331_www2=sac2845; JSESSIONID=B7982AF26D30D28AD6F20CF6E39671C5.cfusion02; ssvbr0327_www2sro=sac2842SRO; sitecorreioscookie-%3FEXTERNO%3Fpool_site_institucional_443=AIBOKIMA; _gat_gtag_UA_564464_1=1; ssvbr0327_www2=sac2848'
};
var dataString = 'acao=track&objetos=JU763467155BR&btnPesq=Buscar';
var options = {
url: 'https://www2.correios.com.br/sistemas/rastreamento/ctrl/ctrlRastreamento.cfm?',
method: 'POST',
headers: headers,
body: dataString
};
function callback(error, response, body) {
if (!error && response.statusCode == 302) {
console.log(body);
console.log(response);
}else{
console.log("a casa caiu");
}
}
request(options, callback);
when I run the script, it returns an empty body, as in the image below https://i.stack.Imgur.com/tjqHl.png
it returns the correct code(302)... but at the time of returning the content, comes nothing, and I tested the same request in Postman, and returned a body with html text.
Good observation, it worked, I put status 200 and took
– gabriel luiz
If you solved your problem, mark the answer as solved, it is not required, but it helps in the experience of the site and new users who will come and have the same question as yours.
– user187421