使用客户端证书和密钥来响应本机POST请求

问题描述

我对React Native和应用程序开发还很陌生。我对向服务(本例中为瑞典BankID)发出POST请求有疑问,该请求需要客户端证书和客户端密钥(.pem / .key文件)才能请求API。

PHP中,我通过卷曲并使用CURLOPT_SSLCERTCURLOPT_SSLKEY并仅从运行PHP的服务器直接读取证书文件来完成了多次。

但是如何在React Native中将fetch()与客户端证书和客户端密钥一起使用? (我正在使用Expo)

我已经尝试过了,但是看到的错误如下:

const options = {
  cert: require("../assets/certs/cert.pem"),key: require("../assets/certs/key.key"),passphrase: "qwerty123",rejectUnauthorized: false,keepAlive: false,};

const sslConfiguredAgent = new https.Agent(options);

try {
  let response = await fetch("https://appapi2.test.bankid.com/rp/v5/auth",{
    method: "POST",headers: {
      Accept: "application/json","Content-Type": "application/json",},body: JSON.stringify({
      personalNumber: "199010240000",endUserIp: "127.0.0.1",}),agent: sslConfiguredAgent,timeoutInterval: 5000,});
  response = await response.json();
  console.log(response);
} catch (err) {
  console.log("Error fetching data-----------",err);
}

enter image description here

我可以在失眠症患者中成功完成请求,如下所示:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)