服务器端Javascript

时间:2018-02-12 10:09:49

标签: javascript curl ssjs

我正在尝试使用http post请求来获取访问令牌。在卷曲中,我得到了这样的工作:

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":"承载"" 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);

在哪里可以将-d派对从有效的卷曲版本中删除?

0 个答案:

没有答案