Node.js 节点获取发送post请求,正文为x-www-form-urlencoded
我想使用节点获取发送post请求,并使用x-www-form中编码的正文负载。我尝试了此代码,但不幸的是它不起作用:Node.js 节点获取发送post请求,正文为x-www-form-urlencoded,node.js,node-fetch,Node.js,Node Fetch,我想使用节点获取发送post请求,并使用x-www-form中编码的正文负载。我尝试了此代码,但不幸的是它不起作用: paypalSignIn = function(){ var username = process.env.PAYPALID; var password = process.env.PAYPALSECRET; var authContent = 'Basic '+base64.encode(username + ":" + password); fetch(
paypalSignIn = function(){
var username = process.env.PAYPALID;
var password = process.env.PAYPALSECRET;
var authContent = 'Basic '+base64.encode(username + ":" + password);
fetch('https://api.sandbox.paypal.com/v1/oauth2/token', { method: 'POST',
headers: {
'Accept': 'application/json',
'Accept-Language' :"en_US",
'Authorization': authContent,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'grant_type=client_credentials' })
.then(res => res.json()) // expecting a json response
.then(json => console.log(json));
}
我不确定这种方式是否可行,但我需要为PayPalAPI使用这个标准。
我的状态代码是400,有错误
grant\u类型为空
Thx我不知道这是否是唯一的错误,但至少在单词
Basic
和编码的用户名/密码之间需要一个空格
下次你问问题的时候,也要发布你的脚本返回的内容。我猜这是一个401错误