2014-07-07 164 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後面的尾部缺少斜線。

現在一切都好了。