将cURL转换为angularjs$http

将cURL转换为angularjs$http,angularjs,curl,Angularjs,Curl,我刚开始学习angularjs,我正试图从api中获取一个令牌。当我在终端中使用curl命令时,它可以很好地工作,并且可以很好地获取令牌。不过,我很难使用$http使其正常工作 下面是我的cURL命令: curl --data "grant_type=authorization_code&client_id=CLIENT_ID&client_secret=SECRET_KEY&redirect_uri=http://localhost:9999&code=AUTH

我刚开始学习angularjs,我正试图从api中获取一个令牌。当我在终端中使用curl命令时,它可以很好地工作,并且可以很好地获取令牌。不过,我很难使用$http使其正常工作

下面是我的cURL命令:

curl --data "grant_type=authorization_code&client_id=CLIENT_ID&client_secret=SECRET_KEY&redirect_uri=http://localhost:9999&code=AUTH_CODE" https://www.twitchalerts.com/api/v1.0/token
有人能帮我用$http转换这个吗

var data = {
    grant_type     :'authorization_code',
    client_id      :'CLIENT_ID',
    client_secret  :'SECRET_KEY',
    redirect_uri   :'http://localhost:9999&code=AUTH_CODE'
};
// Simple GET request example:
$http({
    method: 'GET',//or POST
    url: 'https://www.twitchalerts.com/api/v1.0/token',
    data:data,
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
}, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
如果没有,那么尝试这样做

....
data:data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
....

有关$http$http

的详细信息,请查看
$http
代码的位置。您的错误处理程序告诉您什么?当您尝试发出请求时,您在浏览器控制台中看到了什么?只是它有客户机密钥这一事实表明您可能无法使用ajax实现这一点,因为这将意味着在浏览器
数据
参数
中公开您的凭据对于GET和POST来说是不可互换的,并且GET将没有密码contentType@charlietfl 当您提交for whith方法GET时,enctype=“application/x-www-form-urlencoded | multipart/form data | text/plain”,您是怎么想的,它们会发送哪一个标题?:)GET没有请求主体,因此不需要内容类型。所有数据都在url中