kotlin - Implementing Retrofit on Android Studio - Stack Overflow

I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an e

I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an external API call from my Android app. Now I implemented Retrofit in my project (using the Kotlin language) without sync/compile errors.

When I run my app from the Android Studio emulator and I call a sample API, I obtain the following error:

javax.ssl.SSLHandshakeException: Chain validation failed

I think I'm having some certificate issue, but I don't know how fix it.

I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an external API call from my Android app. Now I implemented Retrofit in my project (using the Kotlin language) without sync/compile errors.

When I run my app from the Android Studio emulator and I call a sample API, I obtain the following error:

javax.ssl.SSLHandshakeException: Chain validation failed

I think I'm having some certificate issue, but I don't know how fix it.

Share Improve this question edited Nov 28, 2024 at 13:44 gre_gor 6,72811 gold badges76 silver badges90 bronze badges asked Nov 28, 2024 at 10:05 TinoTino 13 bronze badges 3
  • 1 Hey, try searching your answers here stackoverflow/a/53297674/17552167 , or else try to cold boot the emulator if you are using it. Or try to check if the API which you are calling is getting called on postman or chrome. If not then you need to fix the URL. Also, if nothing works try to provide your code and also try to change the version of dependency version. – Vishal Shah Commented Nov 28, 2024 at 11:52
  • I searched in stackoverflow/a/53297674/17552167, I restarted the emulator, the API is ok because from Postman it works fine, but nothing helps... – Tino Commented Nov 28, 2024 at 16:09
  • Please provide enough code so others can better understand or reproduce the problem. – melvio Commented Nov 28, 2024 at 17:51
Add a comment  | 

1 Answer 1

Reset to default 0

I resolved in this way:

  1. In my API now I use http instead of https
  2. I created the resource file: res/xml/network_security_config.xml, with: <?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">api.example</domain> </domain-config> </network-security-config>
  3. I edited my AndroidManifest.xml: <application android:networkSecurityConfig="@xml/network_security_config" ... </application>

Now it works!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745517209a4631070.html

相关推荐

  • kotlin - Implementing Retrofit on Android Studio - Stack Overflow

    I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an e

    20小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信