HttpClient无法忽略或绕过自签名证书错误

时间:2019-02-23 10:56:51

标签: angular ionic-framework ionic3 httpclient

我尝试将POST数据发送到服务器,但是收到错误消息“ net :: ERR_CERT_INVALID”。如下所示的代码是我试图绕过该错误的代码,但仍然失败。请帮忙咨询。谢谢。

import { HttpClient, HttpParams } from '@angular/common/http';

createData(data): Promise<any> {
    let post_message = data;
    let header_node = {
      Accept: 'application/json',
      rejectUnauthorized: 'false',
    }
    // this.oauth_header.Authorization = 'Bearer ' + access_token;
    const url_params = new HttpParams()
      .set('rejectUnauthorized', 'false')
      .set('requestCert', 'false')
      .set('insecure', 'true')

    return this.http.post('https://ip/createdata', post_message, {
      headers: header_node,

    }).toPromise();

1 个答案:

答案 0 :(得分:0)

尝试将标头作为HttpHeaders传递到POST方法。

import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';

createData(data): Promise<any> {

    let post_message = data;
    let header_node = {
        headers: new HttpHeaders(
            { 'Accept': 'application/json' },
            { 'rejectUnauthorized': 'false' })
        };

    return this.http.post('https://ip/createdata', post_message, header_node).toPromise();
}