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);
        }
    }

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

  • 相关阅读:
    HTTP下载文件校验失败原因分析与解决
    读《软件测试的艺术》
    CXF wsdl2java 错误
    oracle 存储过程 多参数 多返回值
    ORACLE 函数 调用
    typescript学习入门(学习笔记)
    js常用方法总结
    jenkins安装及项目构建发布回滚
    Centos8中创建LVM精简逻辑卷
    k8s kubectl命令自动补全
  • 原文地址:https://www.cnblogs.com/yaoyuan2/p/10361572.html
Copyright © 2011-2022 走看看