【发布时间】:2016-02-18 22:50:18
【问题描述】:
有人知道如何将下面的 curl 命令翻译成 ajax/xmlhttpsrequest 吗?
curl -d "username=username@company.com&client_secret=123456789&password=pwdgoeshere&grant_type=password&client_id=ReallyLongClientIDGoesHere" -H "Accept: application/json" https://login.salesforce.com/services/oauth2/token
我想实现以下 2 个示例,但我的代码不起作用:
1)
var req = new XMLHttpRequest();
req.open( "POST", "https://login.salesforce.com/services/oauth2/token", true);
req.setRequestHeader('Accept', 'application/json');
req.send();
2)
$.ajax({
url: myUrl,
headers: myHeaders,
type: 'POST',
processData: false,
contentType: false,
}).complete(function ( data ) {
console.log(data.responseText);
});
【问题讨论】:
-
你没有发送帖子数据
-
我不知道我的示例发布数据的格式如何。我对此很陌生
标签: javascript ajax curl oauth-2.0 xmlhttprequest