HttpClient cannot ignore or bypass self signed certificate error

Hello everybody. 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.

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 Like

You could add the self signed certificate to your machine’s trust store. Try the url in the browser first. When you get no more cert error in the browser it should then also work in angular. Google for add self signed certificate to trusted <your operating system>.

1 Like

This error “net::ERR_CERT_INVALID” means the server’s SSL certificate is invalid or not trusted, so the browser blocks your request. Trying to bypass it in code won’t work because browsers enforce SSL security for safety. The proper fix is to install a valid SSL certificate on the server and ensure the full certificate chain (root + intermediate) is configured correctly. You can use Let’s Encrypt for free certificates and check with SSL tools to confirm it’s trusted.

Solution: Update your server to use the correct SSL (fullchain.pem + privkey.pem), restart it, and then test again. Once the certificate is valid and trusted, your POST request will work without needing any bypass code. Hope it helps!

1 Like