Cookie的腐败与多个createHTTPClient钛通话 [英] Cookie corruption with multiple createHTTPClient Titanium calls

查看:178
本文介绍了Cookie的腐败与多个createHTTPClient钛通话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然创造了Appcelerator的钛一款Android应用,既包括web视图和背景电话,我遇到了一个问题/臭虫饼干都拿到多createHTTPClient通话损坏。

While creating an Android app in Appcelerator's Titanium that involves both webView and background calls, I ran into a problem / bug where the cookies were getting corrupted on multiple createHTTPClient calls.

饼干原先从web视图获得的:

Cookies were originally obtained from the webView:

var webview = Ti.UI.createWebView();
webview.url = 'http://www.example.com';
window.add(webview);
webview.addEventListener('load', function(e) {
    cookies = e.source.evalJS("document.cookie");
    Titanium.App.Properties.setString('cookies',cookies);
}
window.open({modal:true});

再后来与背景调用中使用:

and then later used with a background call:

var loader = Titanium.Network.createHTTPClient();  
loader.open("GET",base_url + url); 
loader.onload = function() {
    // process response
}
loader.setRequestHeader('Cookie',Titanium.App.Properties.getString("cookies"));
loader.send(); 

第一次code以上createHTTPClient块叫,一切正常,但随后的上述code的运行就送损坏的饼干。在谷歌应用程序引擎(GAE),打印出的请求头看起来像这样(破):

The first time the above createHTTPClient chunk of code was called, everything worked, but subsequent runs of the above code would send corrupted cookies. In Google App Engine (gae), printing out the request headers would look like this (broken):

logging.info('Request:\n%s' % self.request)

断响应(只请求头的饼干部分示出)

broken response (only the cookie portion of the request header is shown)

饼干: auth=\"eyJfdXNlciI6WzYsMSwiVmRoZEtnYWZRMnNxazFjaVM0U1lKdCIsMTM1NzIyMzcwOSwxMzU3MjIzNzA5XX0\\075|1357223709|4f622167f477a8c82cab196af4b0029af1a966d7\", auth=eyJfdXNlciI6WzYsMSwiVmRoZEtnYWZRMnNxazFjaVM0U1lKdCIsMTM1NzIyMzcwOSwxMzU3MjIzNzA5XX0\\075|1357225569|7a469fab7a38a437649c25620729e07c4607f617
COOKIE2:$版本= 1

工作响应

饼干: auth=\"eyJfdXNlciI6WzYsMSwiVmRoZEtnYWZRMnNxazFjaVM0U1lKdCIsMTM1NzIyMzcwOSwxMzU3MjIzNzA5XX0\\075|1357223709|4f622167f477a8c82cab196af4b0029af1a966d7\"
    ...

Cookie: auth="eyJfdXNlciI6WzYsMSwiVmRoZEtnYWZRMnNxazFjaVM0U1lKdCIsMTM1NzIyMzcwOSwxMzU3MjIzNzA5XX0\075|1357223709|4f622167f477a8c82cab196af4b0029af1a966d7" ...

我怀疑这个问题已经是与UNI code字符或里面的东西 createHTTPClient 。两个 AUTH = 报表显示在损坏的cookie。

I suspect the issue has something to do with unicode characters or something inside createHTTPClient. Two auth= statements are shown in the corrupted cookie.

总之,当应用程序第一次启动时,背景 Titanium.Network.createHTTPClient 通话作品,之后的任何调用呈现一派损坏饼干。

In summary, when the app first launches, the background Titanium.Network.createHTTPClient call works, and any calls after that appear to send corrupted cookies.

推荐答案

了HTTPClient文档说:对象预期用于单个请求,所以我认为多次来电之后一切都将复位。可是,我是第一次通话后不同的。

The HTTPClient documentation says "object is intended to be used for a single request," so I assumed everything would reset after multiple calls. But something was different after the first call.

添加 loader.clearCookies(BASE_URL); 到code之前设置的cookies似乎解决这​​个问题。

Adding loader.clearCookies(base_url); to the code before setting the cookies seems to fix the issue.

var loader = Titanium.Network.createHTTPClient();  
loader.open("GET",base_url + url); 
loader.onload = function() {
    // process response
}
loader.clearCookies(base_url); // THE FIX.
loader.setRequestHeader('Cookie',Titanium.App.Properties.getString("cookies"));
loader.send(); 

这篇关于Cookie的腐败与多个createHTTPClient钛通话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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