2

I'm trying to make a GET request to an api I have that has a JSON Web Token for authentication and takes form-encoded data. It keeps failing with "Network Error" but when I run the same api in cURL, the proper data is returned. Below is my code usign the Axios library:

const token = "xxxxx"; axios.get('https://xxxxxxx.com/route', { headers: { 'Authorization': token, 'Content-Type': 'application/x-www-form-urlencoded' }, data: {} }).then(response => { console.log(response.data); }) .catch((error) => { console.log(error.message); }); 

Working cURL request:

curl -X GET \ https://xxxxxxxx.com/route \ -H 'authorization: xxxxxx' \ -H 'cache-control: no-cache' \ -H 'content-type: application/x-www-form-urlencoded' 

Any help is appreciated!

1 Answer 1

2

Try this. Remove data from headers

 const token = "xxxxx"; axios.get('https://xxxxxxx.com/route', { headers: { 'Authorization': token, 'Content-Type': 'application/x-www-form-urlencoded' } }).then(response => { console.log(response.data); }) .catch((error) => { console.log(error.message); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.