POSTing with JSON using npm request

前端 未结 3 1459
生来不讨喜
生来不讨喜 2021-02-20 11:04

How would one do the following with the request npm module?

curl https://todoist.com/oauth/access_token \\
    -d client_id=0123456789abcdef \\
             


        
相关标签:
3条回答
  • 2021-02-20 11:29
    var url = 'http://xxxxx'
    request({
      url : url,
      method :"POST",
      headers : {
        "content-type": "application/json",
      },
      body: {
        'id':1,
        'name':'xxxx'
      },
      json: true
    },
    

    it's working

    0 讨论(0)
  • 2021-02-20 11:43
    const formData = {
       client_id:     '0123456789abcdef', 
       client_secret: 'secret', 
       code:          'abcdef'
    };
    
    request.post(
      {
        url: 'https://todoist.com/oauth/access_token',
        form: formData
      },
      function (err, httpResponse, body) {
        console.log(err, body);
      }
    );
    

    Please try this code.

    0 讨论(0)
  • 2021-02-20 11:45

    Pretty sure that demo is equivalent to: https://todoist.com/oauth/access_token?client_id=0123456789abcdef&client_secret=secret&code=abcdef&redirect_uri=...

    Where a ? starts the parameters and an & separates them.

    0 讨论(0)
提交回复
热议问题