gpt4 book ai didi

node.js - 使用 npm 请求通过 JSON 发布

转载 作者:IT老高 更新时间:2023-10-28 23:23:01 25 4
gpt4 key购买 nike

如何使用 request npm 模块执行以下操作?

curl https://todoist.com/oauth/access_token \
-d client_id=0123456789abcdef \
-d client_secret=secret \
-d code=abcdef \
-d redirect_uri=https://example.com

我试过这样做:

var body = JSON.stringify({ 
client_id: '0123456789abcdef',
client_secret: 'secret',
code: 'abcdef'
});

var postBody = {
url: 'https://todoist.com/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: 'https://todoist.com/oauth/access_token',
form: formData
},
function (err, httpResponse, body) {
console.log(err, body);
}
);

请试试这个代码。

关于node.js - 使用 npm 请求通过 JSON 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com