我正在尝试一个 http post 请求来获取访问令牌。在 curl 我让它像这样工作:
curl -X POST 'https://www.completeurl.com' -H 'Authorization: Basic base64encodedstroing=' -H 'Content-Type: application/x-www-form-urlencoded' -d grant_type=client_credentials
我在 json 中得到响应:{"access_token":"tokenvalue","token_type":"bearer","expires_in":3600}
到目前为止一切顺利,但现在我必须在 ServerSide Javascript 中完成:
var accessTokenUrl = "https://www.completeurl.com";
var data = "grant_type=client_credentials";
var accessHeaderNames = ["Authorization","Content-Type"];
var apiKey = "mykey";
var apiSecret = "mysecret";
var totalKey = apiKey + ":" + apiSecret;
// we need to Base64 encode the key and secret
var base64encoded = Base64Encode(totalKey);
var tokenMoney = "Basic" + " " + base64encoded;
var accessHeaderNames = ["Authorization","Content-Type"];
var accessHeaderValues = [tokenMoney, "application/x-www-form-urlencoded"];
我应该如何将所有这些放在一起: var accessTokenReply = HTTP.Post(accessTokenUrl,accessHeaderNames,accessHeaderValues);
我在哪里可以把 curl 版本的 -d 派对放在哪里?