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.

Getting 400 Bad Request Error

See original GitHub issue

Issue

Hi, I’m getting 400 when I try to hit my api. The api is working fine. I have validate the API’s via postman and already consuming in the nodejs application but in react-native this is not working.

Here is my code

axios({
            method: 'post',
            url: 'https://api-helper.azurewebsites.net/token',
            data: {
                username: 'api', 
                password: 'MY_PASSWORD', 
                grant_type: 'MY_GRANT_TYPE'
            },
            headers: {
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          }).then((response) => {
            console.log('token', response);
        })
        .catch((response) => console.log('error', response));

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:20
  • Comments:7

github_iconTop GitHub Comments

36reactions
ghostcommented, Jul 30, 2018

Have you tried using this format?

axios.post('https://api-helper.azurewebsites.net/token', {
	username: 'api', 
        password: 'MY_PASSWORD', 
        grant_type: 'MY_GRANT_TYPE'
}, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
})
.then(response => { 
	console.log(response)
})
.catch(error => {
    console.log(error.response)
});
2reactions
KBiswas98commented, Jan 31, 2020

This code Work for me.

.catch((error) => console.log( error.response.request._response ) );

`

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
How to Fix 400 Bad Request Error? · 1. Check the Submitted URL · 2. Clear Browser Cache · 3. Clear Browser Cookies...
Read more >
What is a 400 Bad Request Error (and How Can I Fix It)?
A 400 Bad Request Error occurs when a request sent to the website server is incorrect or corrupt, and the server receiving the...
Read more >
What is HTTP error 400 and how do you fix it? - IT PRO
A 400 Bad Request error is usually a client-side error. A good case in point is a URL string syntax error. Incorrectly typed...
Read more >
How to Fix the 400 Bad Request Error - Lifewire
The 400 Bad Request error means that the request you sent to the website server to view the page was somehow incorrect.
Read more >
400 Bad Request - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request ......
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