【问题标题】:Is it possible to increase the max URI lenght in HttpClient? (Invalid URI: The uri string is too long)是否可以增加 HttpClient 中的最大 URL 长度? (无效的 URI:uri 字符串太长)
【发布时间】:2021-01-18 16:36:47
【问题描述】:

我在Dotnet 5 中使用HttpClient 并尝试创建一个带有很长URI 的查询。我得到了这个例外

Invalid URI: The uri string is too long

我试图弄清楚它的来源,它似乎可以归结为 this line 并带有一个常量:

internal const int c_MaxUriBufferSize = 0xFFF0;

似乎URL长度超过64K实际上是不可能的,但可能有一些我没有弄清楚?

【问题讨论】:

标签: .net url uri dotnet-httpclient .net-5


【解决方案1】:

简而言之:你不能。

如果您查看Uri 的来源,那么原因就很清楚了。

  • 对于 .NET Core,Uri 的源代码位于 this file

在其 GetException method 内部,它转换为 ParsingError.SizeLimit intoUriFormatException

  • 相关资源入口可以在here找到。

所以,如果我们查看Uri 的代码,看看它何时以ParsingError.SizeLimit 失败,那么我们会发现这些:

在前两种情况下,根据c_MaxUriBufferSize (1) 检查限制,其定义如下:

internal const int c_MaxUriBufferSize = 0xFFF0;

在以后的情况下,将根据 ushort.MaxValue 检查限制。

不幸的是,它们都无法改变。

【讨论】:

  • 谢谢你的回答,我想的也是这样……
猜你喜欢
  • 1970-01-01
  • 2011-10-05
  • 2016-01-05
  • 2021-11-28
  • 2021-10-26
  • 2023-03-03
  • 1970-01-01
  • 2012-07-09
  • 1970-01-01
相关资源
最近更新 更多