Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient cannot ignore or bypass self signed certificate error

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();
like image 860
CBV Avatar asked Feb 23 '19 10:02

CBV


1 Answers

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();
}
like image 55
Sudarshana Dayananda Avatar answered Nov 15 '22 03:11

Sudarshana Dayananda