美文网首页我爱编程
typescript与springboot跨域请求

typescript与springboot跨域请求

作者: 纳尔没怒 | 来源:发表于2018-01-12 14:23 被阅读0次

//在项目中添加跨域请求具体配置

@Configuration

public class CorsConfig {

    private CorsConfiguration buildConfig() {

        CorsConfiguration corsConfiguration = new CorsConfiguration();

        corsConfiguration.addAllowedOrigin("*");//设置访问源地址

        corsConfiguration.addAllowedHeader("*");//设置访问源请求头

        corsConfiguration.addAllowedMethod("*");//设置访问源请求方法(get、post等)

        return corsConfiguration;

    }

    @Bean

    public CorsFilter corsFilter() {

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        source.registerCorsConfiguration("/**", buildConfig());// 对接口配置跨域设置

        return new CorsFilter(source);

    }

}

ts和html部分

@Component({

  selector: 'page-home',

  templateUrl: 'home.html'

})

export class HomePage {

  listData: Object;

  constructor(public navCtrl: NavController,public http:Http) {

  }

  printText(){

    this.http.request('http://127.0.0.1:8080/institutions/hello')

    .subscribe((res: Response) => {

      this.listData = res.json();

      console.log(this.listData);

    });

  }

}

相关文章

  • typescript与springboot跨域请求

    //在项目中添加跨域请求具体配置 @Configuration public class CorsConfig {...

  • SpringBoot2.x整合CORS解决跨域问题

    跨域问题系列文章 1. 同源策略与CORS(跨域请求的起源)2. SpringBoot2.x整合CORS解决跨域问...

  • AJAX出现两次请求 options和get|post

    跨域请求 允许跨域请求 preflighted request预请求(options) 跨域请求 XMLHttpR...

  • SpringBoot跨域请求

    1、直接采用SpringBoot的注解@CrossOriginController层在需要跨域的类或者方法上加上该...

  • axios发送俩次请求的原因

    其实跨域分为简单跨域请求和复杂跨域请求 简单跨域请求是不会发送options请求的 复杂跨域请求会发送一个预检请求...

  • 跨域问题

    跨域问题与SpringBoot解决方案 什么是跨域? 定义:浏览器从一个域名的网页取请求另一个域名下的东西。通俗点...

  • 用express实现CORS跨域

    跨域请求头 cors express 跨域请求

  • 跨域

    1、跨域是什么 域指的是域名,向一个域发送请求,如果请求的域和当前域是不同域,就叫跨域;不同域之间的请求就叫跨域请...

  • SpringBoot跨域请求配置

    跨域一直是个比较烦人的事情,不过在JAVA后台简单配置一下就可以了 这样就支持跨域请求了,超级简单

  • SpringBoot 处理跨域请求

    什么是跨域? 由于安全原因,浏览器都遵循着同源原则,拦截了不同域名之间的请求。跨域请求,是指能让不同域名之间,可以...

网友评论

    本文标题:typescript与springboot跨域请求

    本文链接:https://www.haomeiwen.com/subject/juzbnxtx.html