HttpClient cannot ignore or bypass self signed certificate error

爱⌒轻易说出口 提交于 2021-02-07 14:14:06

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/54840830/httpclient-cannot-ignore-or-bypass-self-signed-certificate-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!