Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

578
Visualizações
Setting Cookies VIA NPM requests not working
// Require the request     
const request = require('request');

let api_url = 'https://some-api-that-requires-cookies.com'

// Setup the cookie jar to carry cookies
const cookieJar = request.jar();
let cookie = request.cookie('data=3');
cookieJar.setCookie(cookie);
// Add your cookie to the jar (URL is parsed into cookie parts)


// Send your request and include the cookie jar
request({url: api_url, jar: cookieJar},
    (error, response, body)=>{
        // do things
        console.log(response.headers['set-cookie'])
    }
);

Output:

[
  'sess_id=D8w23-9%!3832ed; Path=/CookieExample; Secure; HttpOnly'
]

my data=3 cookie isn't showing, and my response is still access denied, (the JSON response if data = 3 cookie doesn't exist) IS my cookie not registering? Or is the console log just executing before the cookie is added? any insight is helpful

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

request is fully deprecated, use axios for example.

All of the syntaxes are fully documented on the official npm library.

then:

const axios = require('axios')


axios.get(URL, {
            withCredentials: true, // to able getting cookies from the server back
            headers: {
                // put cookies in here
                Cookie: "cookie1=value; cookie2=value; cookie3=value;"
            }
        }).then(res =>{
          // res.data is your data back
        })
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda