Python 官方文档:入门教程 => 点击学习
目录SpringBoot接收Http请求,参数中+号变成空格小插曲解决get请求中的问题解决post请求中的问题springBoot问题笔记:http请求参数含有特殊符号[]解决方法
+ 在执行URLEncoder.encode(String,"UTF-8")编码后会变成 %2B
+ 在执行URLDecoder.decode(String,"UTF-8")编码后会变成 空格
1.如前端发送的URL中含有“+”那么使用springboot框架接受的参数中 “+”会变成 空格
此时的解决办法是 URLEncoder.encode(参数,"UTF-8")
1.如前端发送的URL中含有“+”那么使用springboot框架接受的参数中 “+”不会变成 空格
此时直接使用该参数就可以
请求报错,调试控制器函数没有触发。
怀疑是请求参数中含有字符 [ ]
由博客了解到是由于Tomcat的新版本中增加了一个新特性,严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ' ( ) ; : @ & = + $ , / ? # [ ])。
@SpringBootApplication
@EnableAsync
public class MainApplication {
public static void main(String[] args)
{
SpringApplication.run(MainApplication.class, args);
}
//允许http请求含有字符[]{}
@Bean
public TomcatServletWEBServerFactory tomcatServletWebServerFactory (){
// 修改内置的 tomcat 容器配置
TomcatServletWebServerFactory tomcatServlet = new TomcatServletWebServerFactory();
tomcatServlet.addConnectorCustomizers(
(TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "[]")
);
return tomcatServlet ;
}
}
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: springboot接收http请求,解决参数中+号变成空格的问题
本文链接: https://www.lsjlt.com/news/133853.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0