gpt4 book ai didi

c# - Microsoft OWIN 测试服务器设置 cookie

转载 作者:太空狗 更新时间:2023-10-29 23:37:54 25 4
gpt4 key购买 nike

我有一个 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 上设置其他属性,例如 HttpOnlySecureDomain

这可能吗?

最佳答案

Cookie 是带有键值项列表的 header 。在您的代码中,它将如下所示:

.Add("Cookie", "cookie1=value1;cookie2=value2")

关于c# - Microsoft OWIN 测试服务器设置 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com