![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
http开发
记录java开发中,http请求相关问题
慢慢来不着急哟
这个作者很懒,什么都没留下…
展开
-
从HttpServletRequest中获取body
注意点是,只能获取一次body如果已经有@RequestBody参数去接body,那么再从request中获取body就会有stream.close的异常正常从流中读取就行了,有多种方式,以下列举一种private static String getBody(HttpServletRequest request) { try (InputStream is = request.getInputStream()) { return IOUtils.toString(is, Sta原创 2021-12-14 15:11:28 · 14762 阅读 · 0 评论 -
response.getWriter().write乱码
加上这句response.setHeader(“Content-Type”,“application/json;charset=UTF-8”);原创 2021-12-14 15:12:07 · 348 阅读 · 0 评论 -
方法参数中带有HttpServletRequest 的controller 用Swagger怎么生成
可以将HttpServletRequest 以成员的方式注入到控制器中,和原来直接加在方法参数里是一个效果。@RestControllerpublic class Controller{ private final HttpServletRequest httpServletRequest; @Autowired public Controller(HttpServletRequest httpServletRequest) { this.httpServletRequest =原创 2021-12-14 15:08:33 · 1789 阅读 · 0 评论 -
HttpClientErrorException处理
ResponseEntity result; HttpEntityentity =new HttpEntity<>(requestJson, headers); try { result =RestConfig.getRestConfig().getRestTemplate().exchange(sendUrl, post, entity, String.class); }catch (HttpClientErrorException e) { result =new Respo.原创 2021-12-14 15:20:22 · 2443 阅读 · 0 评论 -
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternat...
问题原因访问https的网站,没有携带证书解决方案一、忽略证书public RestTemplate dtRestTemplate() { RestTemplate restTemplate = null; try { SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(null, disableSslCheck(), ne原创 2021-12-14 15:19:01 · 4518 阅读 · 0 评论