Harmonyos Next ssl2.pem为正常证书,ssl_error 错误
Harmonyos Next ssl2.pem为正常证书,ssl_error 错误
可以看到我这边是有证书的ssl2.pem为正常证书,ssl_error为错误的
现在我代码无论caPath填写哪个都可以正常获取到服务器返回的数据,好像没用到这个ca
新手求教
HTTPS连接是信任系统预置的CA证书的,得看下服务端的证书是不是在系统预置的CA证书范围内,需要确认下
1、服务端的证书来源,是机构颁发的还是自定义生成的
2、访问的链接和证书可以提供下
async function send(requestData: string, pem: string, host: string, mainHost: string): Promise<LocationInfo> {
let locationInfo: LocationInfo = new LocationInfo()
try {
let options:https.HttpRequestOptions = {
method: https.RequestMethod.POST,
header: {
'Content-Type': 'application/json',
'HOST': mainHost,
'Cache-Control': 'no-cache',
'Accept': '*/*'
},
extraData: requestData,
usingCache:false,
// ca: pem,
// caPath: "/data/storage/el1/bundle/ssl_errr.pem",
caPath: "/data/storage/el1/bundle/ssl2.pem",
connectTimeout: 10 * 1000
}
<span class="hljs-comment">// let httpsRequest = https.createHttps();</span>
<span class="hljs-keyword">let</span> httpsRequest = https.<span class="hljs-title function_">createHttp</span>();
<span class="hljs-comment">// @ts-ignore</span>
<span class="hljs-keyword">let</span> httpResponse = <span class="hljs-keyword">await</span> httpsRequest.<span class="hljs-title function_">request</span>(host + <span class="hljs-string">'/conversion/baseStationToGeo'</span>, options)
logger.<span class="hljs-title function_">debug</span>(<span class="hljs-string">'/// location result:'</span> + httpResponse.<span class="hljs-property">result</span>);
<span class="hljs-keyword">let</span> result = <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">parse</span>(httpResponse.<span class="hljs-property">result</span> <span class="hljs-keyword">as</span> <span class="hljs-built_in">string</span>)
locationInfo.<span class="hljs-property">code</span> = result.<span class="hljs-property">code</span>
locationInfo.<span class="hljs-property">msg</span> = result.<span class="hljs-property">msg</span>
<span class="hljs-keyword">if</span> (locationInfo.<span class="hljs-property">code</span> == <span class="hljs-string">'00000'</span>) {
locationInfo.<span class="hljs-property">code</span> = <span class="hljs-string">'0'</span>
<span class="hljs-keyword">let</span> info = result.<span class="hljs-property">data</span>
<span class="hljs-keyword">if</span> (info.<span class="hljs-property">geo</span>.<span class="hljs-property">length</span> > <span class="hljs-number">1</span>) {
<span class="hljs-keyword">let</span> geos = info.<span class="hljs-property">geo</span>.<span class="hljs-title function_">split</span>(<span class="hljs-string">","</span>)
locationInfo.<span class="hljs-property">longitude</span> = geos[<span class="hljs-number">0</span>]
locationInfo.<span class="hljs-property">latitude</span> = geos[<span class="hljs-number">1</span>]
}
locationInfo.<span class="hljs-property">address</span> = info.<span class="hljs-property">address</span>
locationInfo.<span class="hljs-property">geoCoord</span> = info.<span class="hljs-property">geoCoord</span>
locationInfo.<span class="hljs-property">adcode</span> = info.<span class="hljs-property">adcode</span>
} <span class="hljs-keyword">else</span> {
locationInfo.<span class="hljs-property">code</span> = <span class="hljs-string">'-1'</span>
locationInfo.<span class="hljs-property">msg</span> = httpResponse.<span class="hljs-property">result</span> <span class="hljs-keyword">as</span> <span class="hljs-built_in">string</span>
}
} catch(err) {
logger.error(location exception:<span class="hljs-subst">${<span class="hljs-built_in">JSON</span>.stringify(err)}</span>
)
locationInfo.code = ‘-2’
locationInfo.msg = JSON.stringify(err)
}
return locationInfo
}
caPath
在鸿蒙系统中,caPath
通常用于指定证书颁发机构(Certificate Authority, CA)的路径。这个路径在建立安全连接时至关重要,因为它决定了系统如何验证远程服务器的身份。
在鸿蒙开发过程中,caPath
的设置通常与网络安全配置相关。开发者需要在应用或服务的配置文件中明确指定caPath
,以确保应用能够正确地识别并信任远程服务器提供的证书。
如果caPath
设置不正确,应用可能会遇到SSL/TLS连接错误,如证书验证失败等。这通常会导致应用无法与远程服务器建立安全连接,从而影响应用的正常功能。
在鸿蒙系统中,caPath
的具体设置方式可能因应用类型和开发环境而异。开发者需要参考鸿蒙系统的官方文档,了解如何在自己的开发环境中正确设置caPath
。
值得注意的是,caPath
的设置涉及到应用的安全性,因此开发者需要谨慎处理。确保指定的路径是可信的,并且只包含经过验证的CA证书。
如果开发者在设置caPath
时遇到问题,可以查阅鸿蒙系统的官方文档或相关开发社区以获取更多帮助。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html。