错误请求 - 无效的URL web api

rus*_*shd 4 asp.net-web-api

我正在使用web-api并且我已将web配置文件设置为接受6144作为url的最大长度,如下所示

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime maxUrlLength="6144" 
                 relaxedUrlToFileSystemMapping="true"
                 targetFramework="4.5"/>
Run Code Online (Sandbox Code Playgroud)

当我用299个字符调用api时,一切正常,但是超过299个字符会导致错误的请求 - 无效的URL

示例网址:

http://localhost:56835/api/multibuys/10270001C1001034900|10358419P4001027620|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|10781772P4805004950|

wal*_*wal 6

我自己托管web-api时遇到了同样的问题.我猜你所遇到的限制是UrlSegmentMaxLengthHttp.sys 的默认值.

要解决此问题,您需要在其下添加新的注册表DWORD

HKEY_LOCAL_MACHINE \系统\ CurrentControlSet \服务\ HTTP \参数

在此输入图像描述

打电话UrlSegmentMaxLength给你想要的价值:

UrlSegmentMaxLength 260 0 - 32,766 chars URL路径段中的最大字符数(URL中斜杠之间的区域).如果为零,则它是由ULONG的最大值限制的长度.

参考文献:
https://serverfault.com/questions/66410/iis-6-on-x64-and-long-urls
http://support.microsoft.com/kb/820129