zoukankan      html  css  js  c++  java
  • 报错:The valid characters are defined in RFC 7230 and RFC 3986

    访问 spring boot controller时,报错:The valid characters are defined in RFC 7230 and RFC 3986

    1、特殊符号

    @SpringBootApplication
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
            
            //允许特殊符号,本例是 | { } 做入参,也可追加其他符号
            System.setProperty("tomcat.util.http.parser.HttpParser.requestTargetAllow","|{}");
        }
    }

    新增红色行,解决。

    原因:tomcat9不允许特殊字符传送

    以上解决的是 特殊符号作为参数传递的问题。但是,参数是中文乱码问题,没有解决。

    2、中文乱码

    @Configuration
    public class JsonConfig {
        @Bean
        public HttpMessageConverters fastJsonConfigure() {
            //fastjson
            FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            List<MediaType> fastMediaTypes = CollUtil.newArrayList(MediaType.APPLICATION_JSON_UTF8);
            fastConverter.setSupportedMediaTypes(fastMediaTypes);
            fastConverter.setFastJsonConfig(fastJsonConfig);
            //string(解决传递参数中文乱码)
            StringHttpMessageConverter StringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
            return new HttpMessageConverters(fastConverter,StringConverter);
        }
    }

    添加如上红色行,即可解决。

  • 相关阅读:
    数据库连接池
    Apache- DBUtils框架学习
    权限表的设计
    Java的I/O对文件的操作
    Java下载文件
    Java连接MySQL数据库
    C#用log4net记录日志
    C#多线程和线程池
    C#利用反射动态调用DLL并返回结果,和获取程序集的信息
    CephRGW 在多个RGW负载均衡场景下,RGW 大文件并发分片上传功能验证
  • 原文地址:https://www.cnblogs.com/yaoyuan2/p/10361572.html
Copyright © 2011-2022 走看看