2013-01-10 38 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。