2014-07-07 70 views
0

我试图弄清楚跨域API问题。 我有一个使用Sencha Touch 2.3.1创建的应用程序,它使用Ajax从远程服务器获取数据。 我面临的问题是,针对本地服务器的所有Ajax请求都不包含所有响应头。 在远程服务器上,所有工作正常并且标头都可以。Apache和Headers存在响应Ajax请求

这里有两个打印,显示报头发送和每个服务器individualy

1接收 - 报头发送和从本地主机接收(http://local.api - 虚拟主机)

接头接收:

Connection  Keep-Alive 
Content-Length 274 
Content-Type text/html; charset=iso-8859-1 
Date   Mon, 07 Jul 2014 10:58:54 GMT 
Keep-Alive  timeout=5, max=100 
Location  http://local.api/fa/?ref.agent/lista-clienti&_dc=1404730734262 
Server   Apache/2.2.17 (Win32) PHP/5.3.3 

发送的头文件:

Accept   text/html,application/xhtml+xml, 
       application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding gzip, deflate 
Accept-Language ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2 
Content-Length 33 
Content-Type application/x-www-form-urlencoded; charset=UTF-8 
Host   local.api 
Origin   http://sencha.local 
Referer   http://sencha.local/fisa-agenti/index.html 
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 
       Firefox/30.0 

2 - h发送和从远程服务器接收eaders(http://adgarage.ro

集管接收

Accept-Ranges     bytes 
Access-Control-Allow-Cred... true 
Access-Control-Allow-Orig... * 
Age        0 
Connection      keep-alive 
Content-Length     375 
Content-Type     application/json 
Date       Mon, 07 Jul 2014 10:58:52 GMT 
Server       Apache/2.2.22 (Unix) mod_ssl/2.2.22 
           OpenSSL/0.9.8e-fips-rhel5 
Via        1.1 varnish 
X-Powered-By     PHP/5.3.13 
X-Varnish      562862498 

接头发送

Accept   text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding gzip, deflate 
Accept-Language ro-ro,ro;q=0.8,en-us;q=0.6,en-gb;q=0.4,en;q=0.2 
Host   adgarage.ro 
Origin   http://sencha.local 
Referer   http://sencha.local/fisa-agenti/index.html 
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 
       Firefox/30.0 

注意Access-Controll-Allow报头。 从localhost

收到它从头部容器失踪,这里是我的.htaccess文件:

Header set Access-Control-Allow-Origin * 
Header set Access-Control-Allow-Credentials: true 

这个文件是两台服务器上相同。 我在本地机器上有headers_module活动。

我注意到的另一件事是,从本地响应状态是301 moved Permanently而从远程服务器接收到的响应状态200 Ok

什么我失踪?

谢谢!

回答

0

我发现了这个问题。 正如this topic中所述,由于301 Moved Permanently状态,未发送标头。

我的本地请求是http://local.api/fa?ref.agent/...而不是http://local.api/fa/?ref.agent/... - 请注意第一个链接中/fa后面的尾部缺少斜线。

现在一切都好了。