Kir*_*gen 9 oauth request node.js
如何使用requestnpm模块执行以下操作?
curl https://todoist.com/oauth/access_token \
-d client_id=0123456789abcdef \
-d client_secret=secret \
-d code=abcdef \
-d redirect_uri=https://example.com
Run Code Online (Sandbox Code Playgroud)
我试过这样做:
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) {
...
});
Run Code Online (Sandbox Code Playgroud)
Bla*_*mba 24
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);
}
);
Run Code Online (Sandbox Code Playgroud)
请试试这段代码.
小智 5
var url = 'http://xxxxx'
request({
url : url,
method :"POST",
headers : {
"content-type": "application/json",
},
body: {
'id':1,
'name':'xxxx'
},
json: true
},
Run Code Online (Sandbox Code Playgroud)
它在工作