如何在 tomcat 8.5 的 URL 中允许 ^ 字符 [英] How to Allow ^ character in URLs for tomcat 8.5

查看:27
本文介绍了如何在 tomcat 8.5 的 URL 中允许 ^ 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的请求网址

I have a request URL of below format

http://hostname:port/path&param1={"vars":[{"a":"val1","b":"^"},{"c":"val2","d":"^"}]}&param2=Value3|95|3%20-%206%20Months

我按照这个更改了 catalina.propertiesstackoverflow 问题 .

I changed catalina.properties as per this stackoverflow question .

但根据 tomcat 文档 tomcat.util.http.parser.HttpParser.requestTargetAllow 属性已弃用,relaxedPathCharsrelaxedQueryChars 属性将与连接器标记一起使用.

But as per tomcat documentation tomcat.util.http.parser.HttpParser.requestTargetAllow property is deprecated and relaxedPathChars and relaxedQueryChars attributes are to be used with Connector tag instead.

但是,当我将 xml 文件更改为以下时

However, when i change the xml file to below

 <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="^" relaxedPathChars="^"/>

我仍然收到一个 400 错误的字符请求 ^

I still get a 400 bad request for the character ^

我不确定这是否是正确的配置.

I am not sure if this is the correct configuration.

推荐答案

理想情况下,在将请求发送到服务器之前,您应该始终对查询参数进行 URL 编码.阅读:https:///www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/

Ideally you should always URL-encode your query parameters before sending your request to the server. Read: https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/

如果您想使用轻松查询字符路由,请注意查询中的以下字符也在您应该添加到异常的集合中:" { } [ ] ^ |

If you want to go down the relaxedQueryChars route, note that the following chars from your query are also in the set that you ought to add to the exception: " { } [ ] ^ |

在你的 server.xml 中试试这个:

Try this in your server.xml:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" RelaxQueryChars='^{}[]|&quot;'/>

错误票 62273 上更深入地了解relaxedQueryChars/relaxedPathChars.更改已添加到 Tomat 的所有分支:

More insight into relaxedQueryChars/relaxedPathChars on the bug ticket 62273. The change was added to all branches of Tomat:

  • 9.0.8
  • 8.5.31
  • 8.0.52
  • 7.0.87

我认为您根本不需要relaxedPathChars 属性(这是指URL 路径上的字符).但是,Tomcat 团队的测试结果 似乎暗示以下可用于最大程度的向后兼容性:

I don't think you need the relaxedPathChars attribute at all (this refers to characters on the URL path). However, the Tomcat team's test results seem to suggest that the following could be used for maximum backward-compatibility:

relaxedPathChars='[]|'RelaxQueryChars='[]|{}^&#x5c;&#x60;&quot;<>'/>

nb/查询的第一个参数应该用 ?不是 &

http://hostname:port/path?param1=...&param2=...&param3=...

这篇关于如何在 tomcat 8.5 的 URL 中允许 ^ 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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