本文介绍了HttpClient无法忽略或绕过自签名证书错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have tried to send a POST data to a server but i received an error , "net::ERR_CERT_INVALID". The code as shown below is what I tried to bypass the error but it’s still fail. Please help advice. Thank you.

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();

推荐答案

尝试将标头作为 HttpHeaders 传递给 POST 方法.

Try passing headers as HttpHeaders to POST method.

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();
}

这篇关于HttpClient无法忽略或绕过自签名证书错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:57
查看更多