使用 npm 请求使用 JSON 进行 POST

编程入门 行业动态 更新时间:2024-10-27 02:24:19
本文介绍了使用 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

本文发布于:2023-10-12 01:10:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483337.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:npm   JSON   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!