相关疑难解决方法(0)

为什么我在这里看到"Access-Control-Allow-Origin不允许来源"错误?

我看到以下错误:

Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
Run Code Online (Sandbox Code Playgroud)

使用此代码:

var http = new getXMLHttpRequestObject();
var url = "http://gdata.youtube.com/action/GetUploadToken";
var sendXML = '<?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom"'+
    'xmlns:media="http://search.yahoo.com/mrss/'+
    'xmlns:yt="http://gdata.youtube.com/schemas/2007">'+
    '<media:group><media:title type="plain">My First API</media:title>'+
    '<media:description type="plain">First API</media:description>'+
    '<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category>'+
    '<media:keywords>first, api</media:keywords></media:group></entry>';
http.open("POST", url, true);
http.setRequestHeader("Authorization", "AuthSub token=" + AccessToken);
http.setRequestHeader("X-GData-Key", "key="+ dev_key);
http.setRequestHeader("Content-Type", "application/atom+xml; charset=UTF-8");

http.onreadystatechange = function() {
    if(http.readyState == 4) {
        alert(http.responseXML);
    }
}
http.send(sendXML);
Run Code Online (Sandbox Code Playgroud)

是什么导致这种情况,我该如何解决?

javascript ajax xmlhttprequest youtube-api cors

151
推荐指数
7
解决办法
42万
查看次数

Angular 2 - 请求的资源上没有"Access-Control-Allow-Origin"标头

当我尝试从我的Angular 2 App到我的API进行API调用时,我收到以下错误:

XMLHttpRequest cannot load http://localhost/myAPI/public/api/v1/auth/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 422.
Run Code Online (Sandbox Code Playgroud)

我一直在检查网络上的每一个问题和任何与CORS相关的问题,没有解决我的问题!

我的Laravel API在端口80上运行.(localhost)

我的角度2应用程序在端口3000上运行.(localhost:3000)

  • 我一直在尝试用Cors中间件启用Laravel方面的cors
  • API调用正在使用chrome web security off.这里的第一个答案解决了这个问题,但我真的想在每次测试我的应用时停止使用CMD和不安全的chrome版本.
  • 使用chrome扩展POSTMAN API调用我的API正在运行.

那么......怎么了?为什么我的Angular 2应用程序无法从我的API获取记录?

cors laravel angular

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

cors ×2

ajax ×1

angular ×1

javascript ×1

laravel ×1

xmlhttprequest ×1

youtube-api ×1