springboot绑定https协议如何发起post请求

从小我就黑 2018-11-07 04:23:48
springboot maven项目 刚刚绑定了https协议 但是https发送的都是get请求 但是我们
后台的接口都是post请求的 请问如何将https的get请求转换为post请求
...全文
722 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bigben0123 2019-02-26
  • 打赏
  • 举报
回复
添加一句:
collection.addMethod("post"); //添加post方法


引用 1 楼 从小我就黑 的回复:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
//Due to CONFIDENTIAL and /*, this will cause Tomcat to redirect every request to HTTPS.
//You can configure multiple patterns and multiple constraints if you need more control over what is and is not redirected.

SecurityConstraint constraint = new SecurityConstraint();
constraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addMethod("post"); //添加post方法
collection.addPattern("/*");
constraint.addCollection(collection);
context.addConstraint(constraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;

}
@Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

//Set the scheme that will be assigned to requests received through this connector
//@param scheme The new scheme
connector.setScheme("http");
//Set the port number on which we listen for requests.
// @param port The new port number
connector.setPort(80);

//Set the secure connection flag that will be assigned to requests received through this connector.
//@param secure The new secure connection flag
//if connector.setSecure(true),the http use the http and https use the https;else if connector.setSecure(false),the http redirect to https;
connector.setSecure(false);
//redirectPort The redirect port number (non-SSL to SSL)
connector.setRedirectPort(443);
return connector;
}
这是我跳转https的代码 请大神看一下 非常感谢
寸辰 2018-11-09
  • 打赏
  • 举报
回复
建议把TLS 配置到 nginx上,如果你非得做post->get,可以在nginx上做拦截规则,在nginx上转换Post->Get。
或者通过nginx转发到一个特定接口,自己实现一个Dispatcher,通过自己的接口做dispatch到各个服务
maradona1984 2018-11-09
  • 打赏
  • 举报
回复
不存在https发送的都是get请求,你应该从这个角度去解决问题,而不是修改你的代码
从小我就黑 2018-11-08
  • 打赏
  • 举报
回复
引用 4 楼 wang135139 的回复:
我理解“Request method 'GET' not supported”跟TLS没有关系,你检查一下你的拦截规则和映射关系。拦截规则如果不支持,加支持。如果是映射问题,使用
```
@RequestMapping(xxx, GET)

@GetMapping(xxx)
```

我知道这种方式 但是现在项目已经接近尾声了 所以不能做大批量的操作 所以想问一下有没有一种方法可以将https的默认的get请求转换为post请求
而且我们的都是post请求的 转换为https的get请求参数就没有了 只有post转post参数才会有 我看了一下源码 发现SecurityCollection这个类里面有一个可以添加http请求方式的方法addMethod 所以有没有https的源码可以添加https的请求方式 或者是可以转一下请求方式的方法
寸辰 2018-11-08
  • 打赏
  • 举报
回复
我理解“Request method 'GET' not supported”跟TLS没有关系,你检查一下你的拦截规则和映射关系。拦截规则如果不支持,加支持。如果是映射问题,使用
```
@RequestMapping(xxx, GET)

@GetMapping(xxx)
```
从小我就黑 2018-11-07
  • 打赏
  • 举报
回复
引用 2 楼 wang135139 的回复:
没理解你什么意思,HTTPS 相当于HTTP前边加了TLS,跟请求方式没有关系吧?

是这样的 我在项目上配置了https协议么 然后之前接口都是http的post请求方式 添加https协议后就转换为https的get请求方式 因为接口都是以post请求方式去写的 所以现在所有的后台接口都掉用不了了 提示“Request method 'GET' not supported”请求不了 所以想问一下有什么方法可以让https的get请求变成post请求 这些都是在启动类里面写的
寸辰 2018-11-07
  • 打赏
  • 举报
回复
没理解你什么意思,HTTPS 相当于HTTP前边加了TLS,跟请求方式没有关系吧?
从小我就黑 2018-11-07
  • 打赏
  • 举报
回复
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
//Due to CONFIDENTIAL and /*, this will cause Tomcat to redirect every request to HTTPS.
//You can configure multiple patterns and multiple constraints if you need more control over what is and is not redirected.

SecurityConstraint constraint = new SecurityConstraint();
constraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
constraint.addCollection(collection);
context.addConstraint(constraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;

}
@Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

//Set the scheme that will be assigned to requests received through this connector
//@param scheme The new scheme
connector.setScheme("http");
//Set the port number on which we listen for requests.
// @param port The new port number
connector.setPort(80);

//Set the secure connection flag that will be assigned to requests received through this connector.
//@param secure The new secure connection flag
//if connector.setSecure(true),the http use the http and https use the https;else if connector.setSecure(false),the http redirect to https;
connector.setSecure(false);
//redirectPort The redirect port number (non-SSL to SSL)
connector.setRedirectPort(443);
return connector;
}
这是我跳转https的代码 请大神看一下 非常感谢

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧