CORS not working at all

时光总嘲笑我的痴心妄想 提交于 2019-12-12 04:38:35

问题


The SDK demo works fine (it doesn't need special CORS stuff since it is on the same domain)

When I try to send the request from localhost:8080 this happens

So I'm trying to request api.soundcloud.com/tracks - first my browser sends an OPTIONS req to api.soundcloud.com asking if it's okay to call cross-origin. api.soundcloud.com does not return the headers my browser is looking for so my browser throws an error and can't make the request.

Am I the only person trying to use the APIs from another domain or is something going wrong here?

EDIT: Doing debugging in wireshark - when making an API call using the SDK in the browser an OPTIONS request isn't even being sent. WTF


回答1:


here's a working example where request is coming from jsbin.com:

var request = new XMLHttpRequest();

request.onreadystatechange = function () {
  if (request.readyState === 4 && request.status === 200) {
    console.log(request.responseText);
  }
};
request.open('GET', 'http://api.soundcloud.com/tracks?client_id=YOUR_CLIENT_ID');
request.send();


来源:https://stackoverflow.com/questions/15802249/cors-not-working-at-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!