question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios request fail to authenticate while using headers

See original GitHub issue

Describe the issue Upgrading from 0.18 to 0.19 version is causing an issue in HTTP requests - GET, POST when sending headers like cookie.

Example Code

  const requestOptions = {
    baseURL: 'http://localhost:3000',
    url: `${endPoint}${ids}`,
    method: 'GET',
    responseType: 'json',
    timeout: 100000,
    headers: {
      VerificationToken: userToken,
      Cookie: cookie,
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  };

  axios(requestOptions)
    .then((response) => {
      // Trigger in case, if it is not authenticated
      if (typeof response.data === 'string') {
       console.log('It is working here');
      }else {
       console.log('It should Work here');
      }
    })
    .catch((error) => {
    });

Expected behavior, if applicable Api should return expected result as it was giving in ver 0.18.0`

Environment:

  • Axios Version [e.g. 0.19.0]
  • OS: [e.g. OSX Mojave]
  • Browser [e.g. Chrome [Electron] ]
  • Electron Version [e.g. 4.0.4]

Additional context/Screenshots It is working flawless in ver 0.18.0, but not in ver 0.19.0 if we hit request (GET, POST) that requires headers.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
chinesedfancommented, Mar 28, 2020

Closed due to stale. And feel free to open a new issue if someone met similar problem.

@feed4rz It should be related to #2567 and will be fixed in #2844.

0reactions
feed4rzcommented, Sep 20, 2019

I am having the same problem.

On version 0.18.1 I was able to pass array of cookies ['a=b', 'c=d', ...] to headers option:

axios.get('https://google.com', {
  headers: {
    cookie: ['a=b', 'c=d']
  }
})

And it produced a valid cookie string in headers:

GET / HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\ncookie: a=b; c=d\r\nUser-Agent: axios/0.18.1\r\nHost: google.com\r\nConnection: close\r\n\r\n

But since version 0.19.0 things have changed:

GET / HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\ncookie: [object Object]\r\nUser-Agent: axios/0.19.0\r\nHost: google.com\r\nConnection: close\r\n\r\n

Array of cookies is not getting formatted anymore. Is this a bug or a feature?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axios authentifaction request fails to send header to Spring Boot
I've tried to do it before with simple sending email and password as parameters of GET request and it worked fine, but now...
Read more >
axios not sending cookie | The AI Search Engine You Control
Trying to make requests and send cookies along with it using React and Express. ... axios/axiosAxios request fail to authenticate while using headers#2245....
Read more >
Using Axios to set request headers - LogRocket Blog
We can use Axios interceptors to automatically set the Authorization header for all requests:
Read more >
How to Perform HTTP Requests with Axios – A Complete Guide
Error Handling; POST JSON with Axios; Transforming Requests and Responses; Custom Headers for Request; Config Defaults; Intercept Requests ...
Read more >
Making HTTP requests with Axios - CircleCI
In this response, you get an object of the data that you are expecting, the status code sent back by the server, a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found