Access-Control-Allow-Origin标头存在于请求的资源上

时间:2020-07-03 14:59:26

标签: javascript dropbox

我正在使用javascript通过fetch()方法获取一些数据:

fetch(url, {
      method: 'GET',
      mode: 'cors', 
      cache: 'no-cache',       
      credentials: 'same-origin', 
      headers: myHeaders,
      referrer: 'no-referrer',
     }

但是它给了我以下错误:

错误:- 无法访问来源'http:// localhost:8080'处的https://www.dropbox.com/s/v2pca6kq8nsqmso/abb5c48dae55560e4ae7d41af7bfdc50.jpg?raw=1无法通过访问控制检查:所请求的资源上不存在“ Access-Control-Allow-Origin”标头。如果不透明的响应可以满足您的需求,请将请求的模式设置为“ no-cors”,以在禁用CORS的情况下获取资源。

我想念什么?

1 个答案:

答案 0 :(得分:2)

www.dropbox.com不允许CORS。它不包含CORS标头。这是故意的。
您可以改为在dl.dropboxusercontent.com域使用CDN链接。

请注意,DropBox不支持这种用法,并且可能会或可能不会终止或更改,恕不另行通知。

public struct Coordinates
{
    public Coordinates(string key, string x, string y, string z)
    {
        this.key = key;
        this.x = x;
        this.y = y;
        this.z = z;
    }
    public string key  { get; set; }
    public string x  { get; set; }
    public string y  { get; set; }
    public string z  { get; set; }
    public override string ToString()
    {
        return $"{key} {this.x} {this.y} {this.z}";
    }
}