URL被截断为255个字符 [英] URL getting truncated at 255 characters

查看:140
本文介绍了URL被截断为255个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript小部件,它通过在DOM中创建标记与我的Rails应用程序进行通信。每隔一段时间,我在服务器日志中看到格式错误的请求,其中URL被截断为255个字符:

I have a JavaScript widget which communicates with my Rails app by creating tags in the DOM. Every once in a while, I see a malformed request in my server logs, where the URL is truncated at 255 characters:

http://myapplication.example/mycontroller/1/myaction?hostname=www.mycustomer.example&request[param_a]=3&request[param_b]=1&request[param_c]=0&request[param_d]=0&request[param_e]=3&request[param_f]=1&request[param_g]=4&request[param_h]=0&request[param_i]=5&request

来自Google和Stackoverflow(不同浏览器中URL的最大长度是多少?),看起来255个字符不是URL的有效限制。

From Google and Stackoverflow (What is the maximum length of a URL in different browsers?), it looks like 255 characters is not a valid limit on URLs.

这里是我所知道的:


  • 这是一个零星的问题,并非所有请求都会发生


  • 当发生此错误时,用户代理不会记录在backtrace

这是我不知道的:


  • 此错误发生在哪些类型的浏览器上?也许是一些移动浏览器......

根本导致这个问题的最佳方法是什么?

What's the best way to root cause this problem?

推荐答案

解决根本原因的最佳方法是不要将其作为GET而是作为POST请求。

The best way to solve the Root Cause is to not make it a GET but a POST Request.

AFAIK没有对QueryString的长度设置限制,因此真正的限制是遍布整个地方。我知道4000是某些Web服务器的限制(不记得它是IIS还是Apache以及是否可以更改),但是很有可能某些浏览器的限制要小得多。您没有获得用户代理的事实可能会强调它是移动浏览器,爬虫或其他应用程序而不是真正的浏览器。

There is AFAIK no set limits on the length of a QueryString, so the real limit is all over the place. I know that 4000 is a limit on some web servers (can't remember if it was IIS or Apache and if it could be changed), but it is very possible that some browsers have much smaller limits. The fact that you don't get a user-agent could emphasize that it's a mobile browser, crawler or other application rather than a real browser.

POST请求有点更复杂,但它们可以携带更大的有效载荷,并且可以在服务器端进行配置。

POST requests are a bit more complex to do, but they can carry much bigger "payloads" and can be configured on the server side.

这篇关于URL被截断为255个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆