【问题标题】:HttpClient cannot ignore or bypass self signed certificate errorHttpClient 无法忽略或绕过自签名证书错误
【发布时间】:2019-02-23 10:56:51
【问题描述】:

我尝试向服务器发送 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();

【问题讨论】:

  • 嗨@CBV,你能用角度解决这个错误吗?

标签: angular typescript ionic-framework ionic3 httpclient


【解决方案1】:

尝试将标头作为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();
}

【讨论】:

    猜你喜欢
    • 2011-01-16
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 2012-08-30
    相关资源
    最近更新 更多