在 HttpClientHandler 中设置 MaxConnectionsPerServer 失败
Setting MaxConnectionsPerServer in HttpClientHandler fails
我正在创建一个 Xamarin.Forms 应用程序,它应该在 iOS、Android 和 UWP 上 运行。
此应用程序使用 HttpClient 与其他资源进行通信。 HttpClient 用法封装在 .NET Standard 2.0
库中。该库在其他应用程序中运行良好(主要用于 ASP.NET
环境)。
该库使用了 HttpClientHandler
to configure the HttpClient. Inside of the HttpClientHandler
the sets the MaxConnectionsPerServer
属性 到 1
的实例。这导致 System.ArgumentException
包含以下信息:
Message
:
"Wrong parameter r\n\r\nvalue"
StackTrace
:
at
Windows.Web.Http.Filters.HttpBaseProtocolFilter.put_MaxConnectionsPerServer(UInt32
value)
at
System.Net.Http.HttpClientHandler.set_MaxConnectionsPerServer(Int32
value)
异常中的其余字段是 null
(例如 ParamName
、Source
、...)
在没有引用库的情况下使用也会出现同样的错误。
很容易重现这个错误:
- 创建新的 blanc Xamarin 应用程序
- 在
MainPage
的构造函数中添加一行:
var handler = new HttpClientHandler(){ MaxConnectionsPerServer = 1};
- 运行 Windows 上的应用程序。
我是否遗漏了任何参考或不兼容?
PS:
Xamarin.Essentials: v1.5.3.2
Xamarin.Forms: v4.8.0.1687
Microsoft.NETCore.UniversalWindowsPlattform: v6.2.10
编辑:
参考评论,我的问题不清楚:
1 的值是有意的,根据文档,没有写任何东西,这是不允许的。我们只希望每个服务器有一个连接,而不是更多!此外,在其他环境 (ASP.NET Core
) 中,1 的值完全没问题,不会抛出异常。
那么为什么 Xamarin.Forms 中的行为与其他环境不一致?
Setting MaxConnectionsPerServer in HttpClientHandler fails
请检查MaxConnectionsPerServer
applies to part, this property does not contain UWP platform. I'm afraid it will not work well in UWP platform. for comparing the deafferents, you could check HttpClientHandler
class适用部分,它包含UWP平台。
我正在创建一个 Xamarin.Forms 应用程序,它应该在 iOS、Android 和 UWP 上 运行。
此应用程序使用 HttpClient 与其他资源进行通信。 HttpClient 用法封装在 .NET Standard 2.0
库中。该库在其他应用程序中运行良好(主要用于 ASP.NET
环境)。
该库使用了 HttpClientHandler
to configure the HttpClient. Inside of the HttpClientHandler
the sets the MaxConnectionsPerServer
属性 到 1
的实例。这导致 System.ArgumentException
包含以下信息:
Message
:
"Wrong parameter r\n\r\nvalue"
StackTrace
:
at Windows.Web.Http.Filters.HttpBaseProtocolFilter.put_MaxConnectionsPerServer(UInt32 value)
at System.Net.Http.HttpClientHandler.set_MaxConnectionsPerServer(Int32 value)
异常中的其余字段是 null
(例如 ParamName
、Source
、...)
在没有引用库的情况下使用也会出现同样的错误。
很容易重现这个错误:
- 创建新的 blanc Xamarin 应用程序
- 在
MainPage
的构造函数中添加一行:
var handler = new HttpClientHandler(){ MaxConnectionsPerServer = 1};
- 运行 Windows 上的应用程序。
我是否遗漏了任何参考或不兼容?
PS:
Xamarin.Essentials: v1.5.3.2
Xamarin.Forms: v4.8.0.1687
Microsoft.NETCore.UniversalWindowsPlattform: v6.2.10
编辑:
参考评论,我的问题不清楚:
1 的值是有意的,根据文档,没有写任何东西,这是不允许的。我们只希望每个服务器有一个连接,而不是更多!此外,在其他环境 (ASP.NET Core
) 中,1 的值完全没问题,不会抛出异常。
那么为什么 Xamarin.Forms 中的行为与其他环境不一致?
Setting MaxConnectionsPerServer in HttpClientHandler fails
请检查MaxConnectionsPerServer
applies to part, this property does not contain UWP platform. I'm afraid it will not work well in UWP platform. for comparing the deafferents, you could check HttpClientHandler
class适用部分,它包含UWP平台。