【发布时间】:2015-03-06 17:16:48
【问题描述】:
我正在为 ownCloud 开发一个 Firefox OS 客户端。当我尝试登录并将用户凭据发送到服务器时,我需要获取在每个请求中用于在 ownCloud 中进行身份验证的 cookie 作为响应。
我的问题是,正如我在 Wireshark 中看到的,cookie 是在 HTTP 302 消息中发送的,但我无法在我的代码中读取此消息,因为 Firefox 会自动处理它,并且我读取了没有 cookie 信息的最终 HTTP 200 消息在
request.reponseText;
request.getAllResponseHeaders();
所以我的问题是是否有任何方法可以读取此 HTTP 302 消息标头,或者我是否可以在发送下一个请求之前从 Firefox OS 获取 cookie,甚至让 Firefox OS 自动添加 cookie。我使用以下代码进行 POST:
request = new XMLHttpRequest({mozSystem: true});
request.open('post', serverInput, true);
request.withCredentials=true;
request.addEventListener('error', onRequestError);
request.setRequestHeader("Cookie",cookie_value);
request.setRequestHeader("Connection","keep-alive");
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
request.send(send_string);
if(request.status == 200 || request.status==302){
response = request.responseText;
var headers = request.getAllResponseHeaders();
document.getElementById('results').innerHTML="Server found";
loginSuccessfull();
}else{
alert("Response not found");
document.getElementById('results').innerHTML="Server NOT found";
}
【问题讨论】:
标签: javascript cookies xmlhttprequest firefox-os http-status-code-302