Python 官方文档:入门教程 => 点击学习
目录java调用接口及处理跨域在这记录一个通用的方法调用外部接口引起的跨域问题解决问题java调用接口及处理跨域 在做系统的时候,有些时候系统A的js代码需要调用系统B的接口,这就会
在做系统的时候,有些时候系统A的js代码需要调用系统B的接口,这就会产生跨域现象,可以通过后台调用处理跨域
问题,这就有点 “代理” 的意思了。
public String HttpPost(String urlStr,Map<String,String> params){
URL connect;
StringBuffer data = new StringBuffer();
try {
connect = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection)connect.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);//post不能使用缓存
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("accept", "*
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setMaxAge(3600L);
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.reGISterCorsConfiguration("/**", corsConfig());
return new CorsFilter(source);
}
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: java后台调用接口及处理跨域问题的解决
本文链接: https://www.lsjlt.com/news/143660.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