Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

573
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!