存储和发送http Cookie在PhoneGap应用程序中不起作用 [英] Storing and sending of http cookies not working in PhoneGap app

查看:97
本文介绍了存储和发送http Cookie在PhoneGap应用程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode中开发一个PhoneGap应用程序,使用web api与服务器进行通信。 api接受标准的http请求。作为用户认证过程的一部分,设置cookie,其应当在每个随后的对api的请求的http报头中传输。

I'm developing a PhoneGap app in Xcode that communicates with a server using a web api. The api accepts standard http requests. As part of the user authentication process a cookie is set that is supposed to be transmitted in the http header with each subsequent request to the api.

在对api,我可以清楚地看到一个cookie正作为响应头部的一部分发送回来。但是,它似乎没有被存储,也不会在每个新的api调用的http请求头中发送。

During the login call to the api, I can clearly see that a cookie is being sent back as part of the response header. However, it doesn't seem to get stored, nor does it get sent in the http request header with each new api call.

要调用api,I我使用jQuery的 $。getJSON 调用。

To make calls to the api, I'm using jQuery's $.getJSON call.

我发现了以下问题和答案:phonegap:基于Cookie的身份验证(PHP)无法运行[webview]

I found the following question and answer: phonegap: cookie based authentication (PHP) not working [webview]

上述答案建议在应用程序中将 NSHTTPCookieStorage cookieAcceptPolicy 设置为 NSHTTPCookieAcceptPolicyAlways 委托的 init 。我试过,它似乎并没有解决这个问题。此外,根据 Apple的文档,默认 cookieAcceptPolicy NSHTTPCookieAcceptPolicyAlways

The above answer suggests setting the NSHTTPCookieStorage cookieAcceptPolicy to NSHTTPCookieAcceptPolicyAlways in the app delegate's init. I have tried that and it doesn't seem to solve the issue. Also, according to Apple's documentation, the default cookieAcceptPolicy is NSHTTPCookieAcceptPolicyAlways.

建议如何获取cookie存储和发送工作是非常感谢。

Suggestions on how to get cookie storage and sending working are highly appreciated.

推荐答案

CookieStorage应该并保存cookie,对后续请求。它甚至会自动添加它们,如果你使用,例如,NSURLRequest ...,但是,如果它是为cookie设置的相同的域。

the CookieStorage should and does save the cookie, to be used on subsequent requests. it even adds them automatically if you use, for example, NSURLRequest... but only if it's for the same domain that is set on the cookie.

在类似的问题很多次之前,

I've ran into similar problems many times before,

可能的原因可能是:

1)Cookie有不同的域您在请求上发送的内容(可能是由于重定向),例如,如果请求发送到 http:// www .somesite.com ,其实际上是重定向到 http://somesite.com (这是真正的域名,cookie将被保存为sometime.com网址/域,现在为www.somesite.com

1) the cookie has a different domain that what you are sending on the request, possibly due to a redirect... for example if requests is sent to http://www.somesite.com, which is actually redirecting to http://somesite.com (and that is the real domain name, cookie will be saved for the sometime.com url/domain and now www.somesite.com

2)可能的仅会话和到期日期标题设置不正确的cookie,这导致cookie存储丢弃他们

2) possibly the "session only" and "expiration date" headers are set incorrectly on the cookie, which causes the cookie storage to discard them

希望这有助于,从经验知道cookie存储可能令人沮丧的时候。

hope this helps, know from experience cookie storage can be frustrating at times.

这篇关于存储和发送http Cookie在PhoneGap应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆