我有一个Owin测试服务器:
using (var testServer = TestServer.Create<TestPipelineConfiguration>())
using (var client = new HttpClient(testServer.Handler))
{
client
.DefaultRequestHeaders
.Add("Cookie", $"{AspNetCookies}=HeyThere;");
client.BaseAddress = new Uri("https://testserver/");
var message = client
.PostAsync("print", new StringContent(
jsonProvider.SerialiseObject(new
{
Url = "https://some/url"
}),
Encoding.UTF8, "application/json"))
.Result;
//var message = client.GetAsync("test").Result;
message
.StatusCode
.ShouldBeEquivalentTo(HttpStatusCode.OK);
}
我想在该Cookie上设置其他属性,例如HttpOnly
,Secure
和Domain
。
这可能吗?
答案 0 :(得分:1)
Cookie是包含键值项列表的标头。在您的代码中,它将如下所示:
.Add("Cookie", "cookie1=value1;cookie2=value2")
答案 1 :(得分:1)
属性是cookie值的一部分,分号分隔,例如 “Cookie = cookievalue; path = /; HttpOnly”