Cookies 如何访问所有HTTP响应头

Cookies 如何访问所有HTTP响应头,cookies,http-headers,titanium,titanium-mobile,setcookie,Cookies,Http Headers,Titanium,Titanium Mobile,Setcookie,我有一个钛合金的简单移动应用程序,用来调试登录用户系统的能力 目前,我似乎看不到Set Cookie响应头,因为它总是返回为null 我目前使用的是Tianium SDK 1.7.5(1.8被严重破坏) 我的代码非常简单,是一个使用HTTPClient的教科书示例: var loginReq = Titanium.Network.createHTTPClient(); var url = 'https://auth.csu.edu.au/login/login.pl'; var targetUR

我有一个钛合金的简单移动应用程序,用来调试登录用户系统的能力

目前,我似乎看不到
Set Cookie
响应头,因为它总是返回为
null

我目前使用的是Tianium SDK 1.7.5(1.8被严重破坏)

我的代码非常简单,是一个使用HTTPClient的教科书示例:

var loginReq = Titanium.Network.createHTTPClient();
var url = 'https://auth.csu.edu.au/login/login.pl';
var targetURL = 'http://my.csu.edu.au'

loginButton.addEventListener('click',function(e)
{
    if (username.value != '' && password.value != '')
    {
        loginReq.open('POST', url);

        Ti.API.info('Sending HTTP Request.');

        var params = {
            username: username.value,
            password: password.value,
            url: targetURL
        }

        loginReq.send(params);
    }
    else {
        alert("Username/Password are required");
    }
});

loginReq.onload = function() {
    var cookie = loginReq.getResponseHeader('Set-Cookie');
    Ti.API.info('Response Status: ' + loginReq.status);
    Ti.API.info('Response Header - Cookie: ' + cookie);
    Ti.API.info('Response Header - Location: ' + loginReq.getLocation());

    if (Ti.Platform.osname !== 'android')
        Ti.API.info('Headers: ' + JSON.stringify(loginReq.getResponseHeaders()));

    var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'test.html');
    f.write(this.responseText);

    var webview = Ti.UI.createWebView();
    webview.url = f.nativePath;

    var newWindow = Ti.UI.createWindow();
    newWindow.add(webview);
    newWindow.open({modal:true});
};
结果如下:

[INFO] Sending HTTP Request.
[INFO] Response Status: 200
[INFO] Response Header - Cookie: null
[INFO] Response Header - Location: https://auth.csu.edu.au/login/login.pl?redirect=true&url=http%3a%2f%2fmy%2ecsu%2eedu%2eau
[INFO] Headers: {"Connection":"Keep-Alive","Transfer-Encoding":"Identity","Keep-Alive":"timeout=5, max=99","Content-Type":"text/html","Server":"Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.7d mod_apreq2-20051231/2.6.0 mod_perl/2.0.4 Perl/v5.8.4","Date":"Thu, 02 Feb 2012 01:45:29 GMT"}
我只是在兜圈子,因为我似乎看不出这里到底出了什么问题。让我困惑的是,
HTTPClient.getResponseHeaders()
甚至没有文档记录()——并且不适用于Android

我知道那里一定有东西,因为webview显示的是经过身份验证的页面(除非您获得授权+cookie),否则无法到达那里)


如何获得标题的完整列表,以确保我获得了所有应该获得的标题?

我已经找到了我自己问题的答案

我在代码中返回所有头的内容是正确的。使用
HTTPClient.getResponseHeaders()
对于iOS和
HTTPClient.getAllResponseHeaders()
对于Android是正确的方法(不知道为什么有两种不同的方法-这可能是另一天的问题)

我之所以看不到cookie头,是因为Tianium 1.7.5中有一个bug(在1.8.1中仍然存在)。它不是在302重定向的cookie上转发

关于这些问题的吉拉斯:


谢谢。。这么多。我正要把我的笔记本电脑扔出窗外,但这是一个更好的解决方案。