我有一个简单的qazxsw poi Web Api,我使用qazxsw poi发送一些custum web请求。我这样使用Asp.Net Core
:
HttpClient
我注意到,当我发送多个请求时,HttpClient
会保存在services.AddHttpClient<IMyInterface, MyService>()
...
public class MyService : IMyInterface
{
private readonly HttpClient _client;
public MyService(HttpClient client)
{
_client = client;
}
public async Task SendWebRequest()
{
var url = "https://MyCustomUrl.com/myCustomResource";
var request = new HttpRequestMessage(HttpMethod.Get, url);
var response = await _client.SendAsync(request);
...
}
}
标头中第一次响应时收到的cookie。它将这些cookie添加到连续的请求标头中。 (我用HttpClient
检查过这个)。流:
Set-Cookie
有没有办法强迫fiddler
不添加cookie?
这只发生在同一个会话中,所以如果我要处理//First requst
GET https://MyCustomUrl.com/myCustomResource HTTP/1.1
//First response
HTTP/1.1 200 OK
Set-Cookie: key=value
...
//Second request
GET https://MyCustomUrl.com/myCustomResource HTTP/1.1
Cookie: key=value
//Second response
HTTP/1.1 200 OK
...
那么就不会添加cookie。但处理HttpClient
可能会带来一些其他问题。
见HttpClient
。
获取或设置一个值,该值指示处理程序是否使用CookieContainer属性存储服务器cookie并在发送请求时使用这些cookie。
所以你需要这样做:
HttpClient
如果你在asp.net核心中使用HttpClientHandler.UseCookies
,那么var handler = new HttpClientHandler() { UseCookies = false };
var httpClient = new HttpClient(handler);
建议这样做的方法是:
HttpClientFactory