在我的Google Chrome扩展程序中,我发布了一个如下所示的电话:
public someapiCall(username: string, password: string) {
var url = 'http://test.someTestServer.com/api/user/someApiCall';
let headers = new Headers({
"Content-Type": "application/x-www-form-urlencoded"
});
let options = new RequestOptions({ headers: headers, withCredentials: true });
return this.http.post(url, 'UserName=' + username + '&Password=' + password, options)
.map(res => {
console.log(res);
let cookies = res.headers.getAll('set-cookie');
console.log(cookies);
})
.catch(this.handleError);
}
问题在于,当我调用它时,fiddler会向我显示这些响应标题:
但是当我检查在控制台中打印的Response对象时,它不包含任何引用cookie的头。有谁知道问题在哪里?
答案 0 :(得分:2)
出于安全考虑,大多数Cookie都是仅限HTTP的,请在Cookie标头的末尾查找//global the manage member table
var manageMemberTable;
function updateMember(id = null) {
if(id) {
// click on update button
$("#updatebutton").unbind('click').bind('click', function() {
$.ajax({
url: 'webdesign_action/update.php',
type: 'post',
data: {member_id : id},
dataType: 'json',
success:function(response) {
if(response.success == true) {
$(".removeMessages").html('<div class="alert alert-success alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
'<strong> <span class="glyphicon glyphicon-ok-sign"></span> </strong>'+response.messages+
'</div>');
// refresh the table
manageMemberTable.ajax.reload();
// close the modal
$("#updateModal").modal('hide');
} else {
$(".removeMessages").html('<div class="alert alert-warning alert-dismissible" role="alert">'+
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'+
'<strong> <span class="glyphicon glyphicon-exclamation-sign"></span> </strong>'+response.messages+
'</div>');
// refresh the table
manageMemberTable.ajax.reload();
// close the modal
$("#updateModal").modal('hide');
}
}
});
}); // click remove btn
} else {
alert('Error: Refresh the page again');
}
}
:
httponly
这意味着cookie对JS是隐藏的 - 浏览器将保留它并将其包含在您对域/路径的任何请求中,但客户端JS根本无法访问它。
在Chrome扩展程序中,您可以访问这些Cookie,但不能访问内容脚本或注入代码。
我正在使用chrome-extension-async
获得Set-Cookie:.AspNetCore.Identity.Application=...; expires=...; secure; httponly
/ async
支持,以及chrome.cookies
extension API:
await