Hello to all,
I need to execute a GET via HTTP protocol with OkHttp with referer and user-agent parameters.
If I develop it with VB.NET it works and the server answer to me correctly, but if I try to it with B4A, with this code:
B4X:
Dim hc As OkHttpClient
hc.Initialize("hc")
Dim req As OkHttpRequest
req.InitializeGet("https://MyPageToCall.com")
req.SetHeader("referer", "http://MyPageForReferer.html")
req.SetHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0")
hc.Execute(req, 1)
If I run this code (with correct parameters) hc_ResponseError function is call with Reason = javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Why are you using OkHttpClient directly??????????????????????????
Use OkHttpUtils2 instead.
I guess that the server certificate is unrecognized. You need to modify HttpUtils2Service and initialize hc with hc.InitializeAcceptAll (search the forum for more information).
Ok, as I wrote it works using hc.InitializeAcceptAll("hc") but another user write to me:
Hey mate, be careful with this, because google monitor this behavior and later they can add app as danger.
Try to add some logic inside just for hosts that you need it.
I don't remember any report of such issue. Calling InitializeAcceptAll is indeed problematic as it bypasses the certificate validate. The best solution is to install a trusted certificate on your server.