2013-01-10 37 views
2

我有一個web服務「someWebServiceOnServer」,它發回一個json響應和一個Cookie。如果我通過瀏覽器打這個網址,我看到以下內容:Cookie未保存在Sencha Touch 2中

{"IsAuth":true,"Message":"","UserName":"guest"}

如果我檢查網頁資源 - >餅乾,我看到一個Cookie集。

現在在我的煎茶觸摸2個應用,我如下調用Ajax:

Ext.Ajax.request({
url: 'someWebServiceOnServer',
useDefaultXhrHeader: false,
callback: function(options, success, response) {
console.log(response.responseText)
},
});

在運行,我得到JSON響應預期。但是cookie沒有設置。此外,我無法在響應頭中找到cookie。爲什麼會發生?

注意:CORS已在服務器上實現,我的應用程序可以訪問此服務。我沒有使用withCredentials: true,,因爲這會引發錯誤XMLHttpRequest cannot load . Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.

我的瀏覽器已啓用Cookies。

我需要cookie,因爲我將進行後續調用,將此cookie信息發送回服務器。

+0

問題是否解決?如果是,你能分享你的解決方案嗎? – ThinkFloyd

+0

嗨,我有同樣的問題,你能否提出一個解決方案?非常感謝! – GibboK

+0

看看這個http://stackoverflow.com/questions/11616523/cookie-not-saved-in-sencha-touch-2-application?answertab=active#tab-top它基本上'withCredentials:true,useDefaultXhrHeader:false ' – ThinkFloyd

回答

2

試試這個:

將下列標題添加到服務器響應中。

Access-Control-Allow-Origin: http://clientdomain.com
Access-Control-Allow-Credentials: true

而且在Ajax請求添加withCredentials: true

<system.webServer> 
      <httpProtocol> 
      <customHeaders> 
       <add name="Access-Control-Allow-Origin" value="http://localhost" /> 
       <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" /> 
       <add name="Access-Control-Allow-Credentials" value="true" /> 
      </customHeaders> 
      </httpProtocol> 
     </system.webServer> 

並在Ext.JS請求使用這些參數:

2

對於IIS WCF與ExtJS的請求這適用於web.config中(例如用於本地主機經由SenchaTouch packagedr或這樣的PhoneGap本地託管應用例如) :

​​

這反過來又強制Ext.ajax.request使用cookie。