URI中的斜杠(/)给出了来自Tomcat的HTTP 400错误请求错误

URI中的斜杠(/)给出了来自Tomcat的HTTP 400错误请求错误,tomcat,utf-8,bad-request,Tomcat,Utf 8,Bad Request,我正在使用Tomcat 7.0.54.0 我的应用程序中有一个RESTAPI使用GET方法。在这个API的URI中,有一个斜杠字符(/),我在调用API之前对其进行编码。例如:http://192.168.168.168:38080/myApp/getDetails/test%2Fstring URI参数中的实际字符串是test/string。在调用API之前,我使用了URLEncoder.encode(“test/string”,“UTF-8”),这使我能够test%2Fstring。与我在U

我正在使用Tomcat 7.0.54.0

我的应用程序中有一个RESTAPI使用
GET
方法。在这个API的URI中,有一个斜杠字符(
/
),我在调用API之前对其进行编码。例如:
http://192.168.168.168:38080/myApp/getDetails/test%2Fstring

URI参数中的实际字符串是
test/string
。在调用API之前,我使用了
URLEncoder.encode(“test/string”,“UTF-8”)
,这使我能够
test%2Fstring
。与我在URL中使用的相同

这个API调用在一个环境中运行良好,但在另一个环境中,它给了我一个
HTTP400(错误请求)
错误

Java版本、Tomcat版本、OS环境(Linux)和版本,这两个服务器都是相同的。在
server.xml
中,我对连接器端口进行了如下配置:

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="38080" protocol="HTTP/1.1" redirectPort="8443"/>
当我调试时,我发现请求甚至没有到达这个过滤器。这意味着服务器本身正在限制该URL

这个API以前工作得很好,但最近它开始出现这个问题。唯一的区别是,我使用了相同版本的新Tomcat,并以与现有Tomcat完全相同的方式对其进行了配置


有人能解释发生了什么以及如何解决吗?

我解决了这个问题。我被要求在我的JAVA选项中设置
-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW\u ENCODED\u SLASH=true
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW\u BACKSLASH=true

有关详细信息,请参阅以下内容:

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
    HttpServletRequest httpRequest = null;
    HttpServletResponse httpResponse = null;

    if (request instanceof HttpServletRequest)
    {
        httpRequest = (HttpServletRequest) request;
    }

    if (response instanceof HttpServletResponse)
    {
        httpResponse = (HttpServletResponse) response;
    }

    // it means its not http request
    if (httpRequest == null || httpResponse == null)
    {
        chain.doFilter(request, response);
        return;
    }

    httpRequest.setCharacterEncoding("UTF-8");
    httpResponse.setCharacterEncoding("UTF-8");
    chain.doFilter(request, response);
}