相关配置代码如下:requestHttp(url: string): Promise<string> { return new Promise((resolve, reject) => { getContext(this).area = 0 let context: Context = getContext(this); const keyPemComponent = context.resourceManager.getRawFileContentSync('testCa.pem') let filesDir: string = context.filesDir let filePath = filesDir + "/testCer.pem"; let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); fs.writeSync(file.fd, keyPemComponent.buffer); fs.fsyncSync(file.fd); fs.closeSync(file); let httpRequest = http.createHttp(); httpRequest.request(url, {method: http.RequestMethod.GET, header:{ "Content-Type":"application/json" }, caPath : filePath }, (err: BusinessError, data) => { console.info('url:' + JSON.stringify(url)); if (!err) { //响应耗时时间 console.info('responseCode:' + JSON.stringify(data.responseCode)); console.info('result:' + JSON.stringify(data.result)); } else { console.info('error:' + JSON.stringify(err)); } }) }); }testCa.pem是放在资源目录下的证书,在rawfile目录下。
相关配置代码如下:
testCa.pem是放在资源目录下的证书,在rawfile目录下。