HttpClient 无法忽略或绕过自签名证书错误 [英] HttpClient cannot ignore or bypass self signed certificate error

查看:57
本文介绍了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 无法忽略或绕过自签名证书错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆