pass JSON to HTTP POST Request

后端 未结 9 2050
傲寒
傲寒 2020-11-29 18:22

I\'m trying to make a HTTP POST request to the google QPX Express API [1] using nodejs and request [2].

My code l

9条回答
  •  执笔经年
    2020-11-29 19:03

    According to doc: https://github.com/request/request

    The example is:

      multipart: {
          chunked: false,
          data: [
            {
              'content-type': 'application/json', 
              body: JSON.stringify({foo: 'bar', _attachments: {'message.txt': {follows: true, length: 18, 'content_type': 'text/plain' }}})
            },
          ]
        }
    

    I think you send an object where a string is expected, replace

    body: requestData
    

    by

    body: JSON.stringify(requestData)
    

提交回复
热议问题