{"id":1938,"date":"2023-04-01T10:01:45","date_gmt":"2023-04-01T02:01:45","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1938"},"modified":"2023-04-22T08:46:26","modified_gmt":"2023-04-22T00:46:26","slug":"ruoyi-400-invalid-request-exception-in-chinese-for-the-requested-address","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/ruoyi-400-invalid-request-exception-in-chinese-for-the-requested-address\/","title":{"rendered":"RuoYi\u82e5\u4f9d\u89e3\u51b3\u8bf7\u6c42\u5730\u5740\u5b58\u5728\u4e2d\u6587\u51fa\u73b0400 Invalid request\u5f02\u5e38"},"content":{"rendered":"<p>\u82e5\u4f9d \/ RuoYi \u8bf7\u6c42\u8def\u5f84\u4e2d\u5b58\u5728\u4e2d\u6587\uff0c\u5bfc\u81f4\u8bf7\u6c42\u51fa\u73b0<code>Invalid request<\/code><\/p>\n<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/gitee.com\/y_project\/RuoYi\/issues\/I29QF4\">https:\/\/gitee.com\/y_project\/RuoYi\/issues\/I29QF4<\/a><\/p>\n<p>Shrio1.7.0\u7248\u672c\u624d\u4f1a\u51fa\u73b0\uff0c\u5bf9\u4e8e\u8bf7\u6c42\u5730\u5740\u9700\u8981\u4e2d\u6587\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u505a\u4ee5\u4e0b\u5904\u7406\uff1a<\/p>\n<p>\uff081\uff09\u81ea\u5b9a\u4e49<code>CustomShiroFilterFactoryBean.java<\/code>\uff0c\u8bbe\u7f6e<code>setBlockNonAscii<\/code>\u5c5e\u6027\u4e3a<code>false<\/code><\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">package com.ruoyi.framework.config;\n\nimport org.apache.shiro.spring.web.ShiroFilterFactoryBean;\nimport org.apache.shiro.web.filter.InvalidRequestFilter;\nimport org.apache.shiro.web.filter.mgt.DefaultFilter;\nimport org.apache.shiro.web.filter.mgt.FilterChainManager;\nimport org.apache.shiro.web.filter.mgt.FilterChainResolver;\nimport org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver;\nimport org.apache.shiro.web.mgt.WebSecurityManager;\nimport org.apache.shiro.web.servlet.AbstractShiroFilter;\nimport org.apache.shiro.mgt.SecurityManager;\nimport org.springframework.beans.factory.BeanInitializationException;\nimport javax.servlet.Filter;\nimport java.util.Map;\n\n\/**\n * \u81ea\u5b9a\u4e49ShiroFilterFactoryBean\u89e3\u51b3\u8d44\u6e90\u4e2d\u6587\u8def\u5f84\u95ee\u9898\n * \n * @author ruoyi\n *\/\npublic class CustomShiroFilterFactoryBean extends ShiroFilterFactoryBean\n{\n    @Override\n    public Class&lt;MySpringShiroFilter&gt; getObjectType()\n    {\n        return MySpringShiroFilter.class;\n    }\n\n    @Override\n    protected AbstractShiroFilter createInstance() throws Exception\n    {\n\n        SecurityManager securityManager = getSecurityManager();\n        if (securityManager == null)\n        {\n            String msg = &quot;SecurityManager property must be set.&quot;;\n            throw new BeanInitializationException(msg);\n        }\n\n        if (!(securityManager instanceof WebSecurityManager))\n        {\n            String msg = &quot;The security manager does not implement the WebSecurityManager interface.&quot;;\n            throw new BeanInitializationException(msg);\n        }\n\n        FilterChainManager manager = createFilterChainManager();\n        \/\/ Expose the constructed FilterChainManager by first wrapping it in a\n        \/\/ FilterChainResolver implementation. The AbstractShiroFilter implementations\n        \/\/ do not know about FilterChainManagers - only resolvers:\n        PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();\n        chainResolver.setFilterChainManager(manager);\n\n        Map&lt;String, Filter&gt; filterMap = manager.getFilters();\n        Filter invalidRequestFilter = filterMap.get(DefaultFilter.invalidRequest.name());\n        if (invalidRequestFilter instanceof InvalidRequestFilter)\n        {\n            \/\/ \u6b64\u5904\u662f\u5173\u952e,\u8bbe\u7f6efalse\u8df3\u8fc7URL\u643a\u5e26\u4e2d\u6587400\uff0cservletPath\u4e2d\u6587\u6821\u9a8cbug\n            ((InvalidRequestFilter) invalidRequestFilter).setBlockNonAscii(false);\n        }\n        \/\/ Now create a concrete ShiroFilter instance and apply the acquired SecurityManager and built\n        \/\/ FilterChainResolver. It doesn&#039;t matter that the instance is an anonymous inner class\n        \/\/ here - we&#039;re just using it because it is a concrete AbstractShiroFilter instance that accepts\n        \/\/ injection of the SecurityManager and FilterChainResolver:\n        return new MySpringShiroFilter((WebSecurityManager) securityManager, chainResolver);\n    }\n\n    private static final class MySpringShiroFilter extends AbstractShiroFilter\n    {\n        protected MySpringShiroFilter(WebSecurityManager webSecurityManager, FilterChainResolver resolver)\n        {\n            if (webSecurityManager == null)\n            {\n                throw new IllegalArgumentException(&quot;WebSecurityManager property cannot be null.&quot;);\n            }\n            else\n            {\n                this.setSecurityManager(webSecurityManager);\n                if (resolver != null)\n                {\n                    this.setFilterChainResolver(resolver);\n                }\n\n            }\n        }\n    }\n}<\/code><\/pre>\n<p>\uff082\uff09\u66ff\u6362<code>ShiroConfig.java<\/code>\u4e2d\u7684\u8fc7\u6ee4\u5668\u914d\u7f6e\u4e3a\u81ea\u5b9a\u4e49<\/p>\n<pre><code class=\"language-java\">\/\/ \u9ed8\u8ba4\u7684\nShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();\n\nShiroFilterFactoryBean\u66f4\u6362\u4e3aCustomShiroFilterFactoryBean\n\n\/\/ \u81ea\u5b9a\u4e49\u7684\nCustomShiroFilterFactoryBean shiroFilterFactoryBean = new CustomShiroFilterFactoryBean();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u82e5\u4f9d \/ RuoYi \u8bf7\u6c42\u8def\u5f84\u4e2d\u5b58\u5728\u4e2d\u6587\uff0c\u5bfc\u81f4\u8bf7\u6c42\u51fa\u73b0Invalid request \u53c2\u8003\uff1ahttps:\/\/g [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-1938","post","type-post","status-publish","format-standard","hentry","category-ruoyi"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1938"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1938\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}