有任何配置可以增加 Azure API 管理的 URL 最大长度 (APIM)?

Any configuration to increase URL max length for Azure API Management (APIM)?

我有一个使用 Azure API 管理的 REST API,并且在使用大型查询字符串进行测试时,注意到一旦 URL 超过大约 1800 个字符, APIM 不会路由请求,而是发回一个错误 "Resource not found" 和状态代码 400。当我 运行 将相同的请求直接发送到本地的 REST 端点时,它工作正常(我在 Program.cs 文件中增加了 Kestrel 服务器最大请求长度:

WebHost.CreateDefaultBuilder(args)
                .ConfigureKestrel((context, options) =>
                {
                    options.Limits.MaxRequestLineSize = 2147483647;
                    options.Limits.MaxRequestBufferSize = 2147483647;
                })
                .UseStartup<Startup>();

我可以为 azure APIM 做类似的配置来增加允许的最大 URL 大小吗?

如果您使用的是 GET 方法,则限制为最多 2,048 个字符,减去实际路径中的字符数,所以我建议您检查路径长度和您的 URL长度。 URL 的最大长度受不同浏览器的限制。

您可以查看此线程,解释不同浏览器的 URL 的长度问题:

What is the maximum length of a URL in different browsers?

Windows 支持的所有文件系统都使用文件和目录的概念来访问存储在磁盘或设备上的数据。 Windows 使用文件和设备 Windows API 的开发人员 I/O 应该了解文件和目录名称的各种规则、约定和限制。

您可以通读以下文档以了解以下文档中服务器的路径长度限制:

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maxpath

另外,这里有一个类似的讨论 URL query string length while consuming APIM,请检查它是否有帮助,根据结论“当路径的任何一部分是时,长度问题都会存在超过 261 个字符”@MisterHux 建议:

希望对您有所帮助。

所以回答我自己的问题:

联系了 Microsoft 支持,他们承认这是 APIM 消费层的限制。一种解决方法是切换到不同的层。我已经复制了我从下面的 azure 支持人员那里得到的回复:

Root Cause:

For the previous investigation, this ticket is about the consumption tier url limitation.

  1. As this configuration for the max URL length cannot be changed from the APIM policies. At this moment, the consumption tier have this limitation from our backend setting which is already written into the main configuration.

  2. The consumption tier's url limit is like below. max url length: 4096 max query string length: 2048

The space will be changed as %20 which is 3 characters.

  1. The developer, basic and premium tier of APIM use the same backend structure and the restriction will not exist in this tiers different from the consumption tier. These tiers will have over 10K url length.