Skip to content

JSON Post not working #856

Closed
Closed
@burakuluu

Description

@burakuluu

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?

Activity

burakuluu

burakuluu commented on Apr 24, 2017

@burakuluu
Author

My problem is solved by this answer

locked and limited conversation to collaborators on May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @burakuluu

        Issue actions

          JSON Post not working · Issue #856 · axios/axios