最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cross-Subdomain Requests - Stack Overflow

programmeradmin9浏览0评论

I have two URLs:

One is the application URL = One is the application API URL = /

How can I get the application to be able to request things from the api at a different subdomain.

I have already tried putting Access-Control-Allow-Origin: * on both sides with no luck.

Thanks

I have two URLs:

One is the application URL = http://domain./app One is the application API URL = http://api.domain./

How can I get the application to be able to request things from the api at a different subdomain.

I have already tried putting Access-Control-Allow-Origin: * on both sides with no luck.

Thanks

Share Improve this question asked Jun 22, 2012 at 17:48 JeffJeff 9432 gold badges10 silver badges17 bronze badges 1
  • It might help : stackoverflow./a/11072639/705773 – Ajinkya Commented Jun 22, 2012 at 17:50
Add a ment  | 

2 Answers 2

Reset to default 5

The two servers (not the client) need to send the following headers:

  1. Access-Control-Allow-Origin : Decide which origin could call into the server
  2. Access-Control-Allow-Methods : The method that is allowed to access the resource (GET or POST)
  3. Access-Control-Max-Age : How long the cache is held

You could inspect the headers returned from the server (using Firebug or others) if the servers are supporting cross origin resource sharing.

If you can't modify the two servers to add the headers, one other possibility to set up a proxy that sit between your request and two servers. This proxy could add the headers if you need to access them

If you own admin right to the servers, this CORS page shows how to add the headers in various platforms.

set the cookie domain to .domain. and you should be all set.. This is what I have done in my application..

发布评论

评论列表(0)

  1. 暂无评论