Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Post not working #856

Closed
burakuluu opened this issue Apr 24, 2017 · 1 comment
Closed

JSON Post not working #856

burakuluu opened this issue Apr 24, 2017 · 1 comment

Comments

@burakuluu
Copy link

burakuluu commented Apr 24, 2017

I have a link like;

http://10.254.147.183:7777/auth/oauth/token?grant_type=password&username=demo&password=12345

and I want to write the parameters of this link into a variable. I mean those 3 parameters, which are grant_type, username and password should be sent as a variable.

I tried to convert it to a variable but it didn't work when I put the variable into the post method.

My variable looks like;

    const x = {
      grant_type:'password',
      username:'demo',
      password:'12345'
    }

My post method;

axios.post('http://10.254.147.183:7777/auth/oauth/token',x, {
      headers: { 'Content-Type': ['application/x-www-form-urlencoded'], 'Authorization': ['Basic Y2xpZW50OnNlY3JldA=='] }
    })
    .then(function(response){
      console.log(response.data);
      console.log(response.status);
    })
    .catch(function(error){
      console.log(error);
    });

When I write the code below, it works but when I write the code above it doesn't.

axios.post('http://10.254.147.183:7777/auth/oauth/token','grant_type=password&username=demo&password=12345', {
      headers: { 'Content-Type': ['application/x-www-form-urlencoded'], 'Authorization': ['Basic Y2xpZW50OnNlY3JldA=='] }
    })
    .then(function(response){
      console.log(response.data);
      console.log(response.status);
    })
    .catch(function(error){
      console.log(error);
    });

Could you tell me how to send those parameters as a variable?

@burakuluu
Copy link
Author

My problem is solved by this answer

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant