发出HTTP请求时出现Access-Control-Allow-Origin错误 [英] Access-Control-Allow-Origin error when making a HTTP request

查看:149
本文介绍了发出HTTP请求时出现Access-Control-Allow-Origin错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在通过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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆