本文介绍了使用 npm 请求使用 JSON 进行 POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 request npm 模块执行以下操作?
How would one do the following with the request npm module?
curl todoist/oauth/access_token \ -d client_id=0123456789abcdef \ -d client_secret=secret \ -d code=abcdef \ -d redirect_uri=example我试过这样做:
var body = JSON.stringify({ client_id: '0123456789abcdef', client_secret: 'secret', code: 'abcdef' }); var postBody = { url: 'todoist/oauth/access_token', body: body, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; request.post(postBody, function(error, response, body) { ... }); 推荐答案 const formData = { client_id: '0123456789abcdef', client_secret: 'secret', code: 'abcdef' }; request.post( { url: 'todoist/oauth/access_token', form: formData }, function (err, httpResponse, body) { console.log(err, body); } );请试试这个代码.
更多推荐
使用 npm 请求使用 JSON 进行 POST
发布评论