http请求中的caPath路径该如何指定?

当前把证书安排在hsp里面,在base/common/src/main/resources/rawfile/spdbccc.cer,http请求中,caPath该如何指定?

HarmonyOS
2024-08-22 21:28:29
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请求时capath参数设置证书路径可参考如下:

requestHttp(url: string): Promise<string> { 
  //文件方式写入pem(导入证书需要放在rawfile资源目录下) 
  getContext(this).area = 0 
  let context: Context = getContext(this); 
  const keyPemConent = context.resourceManager.getRawFileContentSync('_.cnfic.com.cn.pem') 
  let filesDir: string = context.filesDir 
  let filePath = filesDir + "/testCer2.pem"; ///etc/ssl/certs/cacert.pem /storage/media/100/local/files/Docs/Download/charles-ssl-proxying-certificate.pem 
  let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 
  fs.writeSync(file.fd, keyPemConent.buffer); 
  fs.fsyncSync(file.fd); 
  fs.closeSync(file); 
 
  return new Promise((resolve, reject) => { 
  let httpRequest = http.createHttp(); 
  httpRequest.request( 
  url, 
  { 
  method: http.RequestMethod.GET, 
  connectTimeout: 60000, 
  readTimeout: 60000, 
  //抓包参数设置 
  usingProxy:true, 
  caPath :filePath , // "/data/local/tmp/NewFile.pem" 
}, (err: BusinessError, data) => { 
  console.info('1---- url:' + JSON.stringify(url)); 
  if (!err) { 
    // data.result为HTTP响应内容,可根据业务需要进行解析 
    console.info('1---- arrResult:' + JSON.stringify(data.result)); 
    let obj: object = JSON.parse(JSON.stringify(data.result)); 
    console.info('1---- header:' + JSON.stringify(data.header)); 
    console.info('1---- cookies:' + JSON.stringify(data.cookies)); 
    console.info('1---- code:' + JSON.stringify(data.responseCode)); 
    httpRequest.destroy(); 
  } else { 
    console.info('1---- error:' + JSON.stringify(err)); 
    console.info("1 ---------------------------------------------") 
    httpRequest.destroy(); 
  } 
}) 
}); 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-08-23 16:52:31
相关问题
HarmonyOS httpRequestcaPath路径写法
668浏览 • 1回复 待解决
应用http请求响应2300023
3269浏览 • 1回复 待解决
HarmonyOS http请求封装
946浏览 • 1回复 待解决
ArkTSHTTP请求如何以JSON形式进行传输
3890浏览 • 1回复 待解决
求告知如何发起HTTP请求
1271浏览 • 1回复 待解决
http 请求 如何cookie持久化?
2893浏览 • 1回复 待解决
HTTP GET请求如何传递参数?
4146浏览 • 1回复 待解决
HarmonyOS C++如何读取指定路径文件
722浏览 • 1回复 待解决
HarmonyOS 取消http请求
1176浏览 • 1回复 待解决
HarmonyOS http请求封装
901浏览 • 1回复 待解决
如何使用arkts进行http请求通信
274浏览 • 0回复 待解决
http请求报错2300006如何解决
3956浏览 • 1回复 待解决