【问题标题】:Changing Timeout on HttpClient of Microsoft.Owin.Testing.TestServer has no effect在 Microsoft.Owin.Testing.TestServer 的 HttpClient 上更改超时没有效果
【发布时间】:2019-01-24 10:06:54
【问题描述】:

我正在使用 .net 461、Microsoft.AspNet.WebApi 5.2.3

var testServer = Microsoft.Owin.Testing.TestServer.Create<MyConfig>();

//this has no effect, and Timeout is still the default 100 seconds
testServer.HttpClient.Timeout = TimeSpan.FromSeconds(200); 

如果我这样做,那么设置就会生效:

var client = new HttpClient
{
   BaseAddress = new Uri("baseaddress")
};

client.Timeout = TimeSpan.FromSeconds(200); // this change has effect

为什么我不能在第一个 sn-p 上更改 TimeOut 属性?

【问题讨论】:

    标签: c# asp.net-web-api httpclient


    【解决方案1】:

    https://docs.microsoft.com/en-us/previous-versions/aspnet/dn782655(v%3dvs.113)

    HttpClient
    返回一个新的 HttpClient,它包装了 Handler 并且是 能够向 OWIN 管道提交请求。

    所以每次调用testServer.HttpClient 时,都会为您创建一个新的HttpClient 实例,这就是您的更改无效的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-31
      • 2015-05-21
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多