OData URL 长度限制

发布于 2024-10-03 10:23:13 字数 158 浏览 4 评论 0原文

浏览器对 URL 的长度有限制。 IE 有限制,Url 长度不能超过 2K 个字符。

当我形成 $filter equals 查询时,我可以与多个输入值进行比较。在这种情况下,Url 的长度将超过 2K。

OData 对 Url 的长度有限制吗?

谢谢

Browsers have limitation on the length of the URLs. IE has limitation that Url length should not exceed 2K characters.

When I form a $filter equals query, I could compare with multiple input values. In such a case the length of the Url would exceed 2K.

Does OData sets any limits on the length of the Url?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

病毒体 2024-10-10 10:23:13

OData 本身不限制 Url 的长度,但正如您所指出的,大多数客户端和服务器都会这样做。因此,通常最好不要生成太长的 URL。

您提到的问题(实现 Contains 运算符或类似的东西)有两种可能的解决方法:

1)使用服务操作来为您处理此类查询。您可以传递编码为字符串或类似内容的多个输入值,或者服务操作可能预先知道这些值。

2)使用长$filter,但在$batch请求中发送请求。优点是 Url 的限制要大得多,而且您不太可能会达到它。缺点是,即使您尝试执行 GET 请求,由于 $batch 它会作为 POST 请求通过网络传输,因此不会被缓存。

OData itself doesn't limit the length of the Url, but as you noted most clients and servers do. So usually it's a good practive to not produce URLs too long.

The problem you refer to (implementing the Contains operator, or something similar) has two possible workarounds:

1) Use service operation to handle such query for you. You can possibly pass the multiple input values encoded as a string or something like that, or maybe the service operation knows these up front anyway.

2) Use the long $filter, but send the request in a $batch request. The advantage is that the limit on the Url is much bigger and it's very unlikely you will hit it. The disadvantage is that even though you're trying to execute a GET request, due to the $batch it travels as POST request over the web and thus it won't be cached.

梦言归人 2024-10-10 10:23:13

我尊重@Vitek对OP问题的回答

OData本身不限制Url的长度

,但是如果其他人由于 IIS 限制 到达这里:请求过滤模块配置为拒绝查询字符串太长的请求。,他们可能会从我的回答中受益。按照该错误的说明进行操作:

验证 applicationhost.config 或 web.config 文件中的 configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString 设置。

按照说明进行操作:

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="50000">
        </requestLimits>
        ...

您也可能会收到此错误:
此请求的查询字符串长度超出了配置的 maxQueryStringLength 值。

此技术的描述如下:此处这里,它看起来像这样:

<configuration>
    <system.web>
        <httpRuntime maxQueryStringLength = "50000" ... />

I defer to @Vitek's answer to the OP's question:

OData itself doesn't limit the length of the Url

But if others who arrive here because of IIS limitations : The request filtering module is configured to deny a request where the query string is too long., they may benefit from my answer. Follow that error's instructions:

Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting in the applicationhost.config or web.config file.

Follow the instructions:

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="50000">
        </requestLimits>
        ...

You may also get this error:
The length of the query string for this request exceeds the configured maxQueryStringLength value.

This technique is described here and here, and it looks like this:

<configuration>
    <system.web>
        <httpRuntime maxQueryStringLength = "50000" ... />
森罗 2024-10-10 10:23:13

我没有找到$batch是如何使用的。所以我使用 $filter 来发送长请求。它非常简单:

DataServiceQuery<CLIENT> ordersQuery = DataServiceQuery<CLIENT>)this.context.CLIENTS.AddQueryOption("$filter", MyFilter());

其中 MyFilter() 返回如下字符串:"ID_CLIENT = 1 or ID_CLIENT = 2"

注意:不要使用大写 AND。它会导致错误。使用 and 而不是 AND

I didn't find how the $batch is used. so I used $filter for sending a long request. Its pretty easy:

DataServiceQuery<CLIENT> ordersQuery = DataServiceQuery<CLIENT>)this.context.CLIENTS.AddQueryOption("$filter", MyFilter());

where MyFilter() return a string like this: "ID_CLIENT = 1 or ID_CLIENT = 2"

NB: Dont use the uppercase AND. it leads to and error. use and not AND

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文