Angular 2 HTTPs POST ERROR在IE 11中

时间:2017-01-09 16:10:14

标签: angular internet-explorer-11

我正在使用角度2来打电话。

create() {
    let headers = new Headers({ 'Content-Type': 'text/plain' });
    let options = new RequestOptions({ headers: headers });
    let body = JSON.stringify({message:'[START]});
    this.http.post('https://localhost:8888/client/get', body, options)
        .map(res => res.json())
        .subscribe(
            data => console.log(data) ,
            err => console.log(err)         
        );
}

使用http://localhost:8888/client/get时效果很好,但是当我尝试使用https://localhost:8888/client/get进行发布呼叫时,我收到以下错误:

enter image description here

其余的Web服务是在spring boot上构建的。我使用自签名证书通过https协议访问localhost。我按照this文章中提供的步骤通过https访问localhost。

请告知如何解决此问题。

1 个答案:

答案 0 :(得分:0)

我使用不同的URL测试了同一段代码,该URL具有正在运行的正确证书。因此很明显,问题在于证书。作为一种解决方法,我使用了本文提供的建议 http://jonnyreeves.co.uk/2013/making-xhr-request-to-https-domains-with-winjs/

以下是有角度的解决方法;

  ngOnInit() {
        this.get();
     }

get(){
     let headers = new Headers({ 'Content-Type': 'application/json' });
     let options = new RequestOptions({ headers: headers });
     this.http.get('https://localhost:8888',options);
}
create() {
    let headers = new Headers({ 'Content-Type': 'text/plain' });
    let options = new RequestOptions({ headers: headers });
    let body = JSON.stringify({message:'[START]});
    this.http.post('https://localhost:8888/client/get', body, options)
        .map(res => res.json())
        .subscribe(
            data => console.log(data) ,
            err => console.log(err)         
        );
}

调用get方法后,我们可以使用post方法。