我正在开发一个与安全的.net服务器通信的PhoneGap应用程序.问题是,我似乎无法通过任何Cookie传递任何Cookie(W3C).
这就是我正在做的(假设"用户名"和"密码"工作).
var token;
$.ajax({
url: "https://server.com/AuthService/api/account/login",
crossDomain: true,
type: 'post',
async: false,
data: {
username: "username",
password: "password"
}
}).done(function(response) {
token = response.securityToken;
success = true;
});
Run Code Online (Sandbox Code Playgroud)
此时我有一个身份验证令牌,可用于验证所有后续请求.所以使用该令牌我向服务器发出另一个请求......
$.ajax({
url: "https://server.com/Service/api/search?query=" + query,
headers: { Cookie: 'auth=' + token },
crossDomain: true,
withCredentials: true,
type: 'POST',
async: false,
data: ' ' //because we don't want our request to be 0 bytes (the server is picky)
}).done(function(data) {
result = data;
});
Run Code Online (Sandbox Code Playgroud)
Chrome只是说:拒绝设置不安全的标题"Cookie"(符合W3C规范).应用程序未设置标头,因此请求401s,因为未发送授权cookie.
我的问题是:有没有办法颠覆这个并覆盖PhoneGap上的Cookie标题(或其他完全解决方法)?我知道使用Authorization标头也是一个选项,但我对服务器的访问权限有限(不支持它),并且希望有更直接的解决方案.
奖金问题:对AuthService的调用还应该在设备上设置一个httpOnly cookie,但不是(我推测这是因为它是跨域请求)...我在这个假设中是否正确,或者是否有错误服务器端?
谢谢!