发出HTTP请求时出现Access-Control-Allow-Origin错误 [英] Access-Control-Allow-Origin error when making a HTTP request
问题描述
您好我正在通过OAuth 2.0对用户进行身份验证,并且我收到了Access-Control-Allow-Origin错误( XMLHttpRequest无法加载https://www.box.com发出以下POST请求时,/ api / oauth2 / token.Initial http:// localhost不允许由Access-Control-Allow-Origin。
):
Hi I'm in the process of authenticating a user via OAuth 2.0 and I'm getting a Access-Control-Allow-Origin error (XMLHttpRequest cannot load https://www.box.com/api/oauth2/token. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
) when making the following POST request:
var xhr=new XMLHttpRequest();
xhr.open('POST',path,true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.onload = function() {
var text = xhr.responseText;
alert('Response from request to ' + path + ': ' + text);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send(params);
任何帮助将不胜感激!我查看了CORS,JSONP,并添加了回调=?到网址,但我尝试过的任何工作都没有。
Any help would be greatly appreciated! I've looked into CORS, JSONP, and adding callback=? to the url but nothing I've tried is working.
推荐答案
http://developers.box.com/docs/
Box API在
app-by-app的基础上支持CORS。如果您正在构建需要CORS的应用程序,
请与我们联系,并附上您的用例说明。
The Box API supports CORS on an app-by-app basis. If you’re building an application that needs CORS, please contact us with a description of your use case.
这篇关于发出HTTP请求时出现Access-Control-Allow-Origin错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!