-1

Can anyone please show me the way to fetch data from localhost by OkHttp in Kotlin. When i changed url to https, it worked well

Picture in Logcat for successful one

but when i use http://localhost..., it failed to execute

Picture when failed

  • 1
    Please improve the question and attached the picture again. – youDaily Aug 28 '18 at 05:52
  • Possible duplicate of [How to connect to my http://localhost web server from Android Emulator in Eclipse](https://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator-in-eclips) – Rizwan Aug 28 '18 at 05:54

1 Answers1

2

EDIT - 8/23/22

It is likely you need to set

android:usesCleartextTraffic="true"

as a flag within the <application> element in the AndroidManifest.xml file.

Old Answer

don't use localhost like this. open command prompt if you are using Windows. type ipconfig and then get Local Ip Address and then use that Ip Address to get data from local host. same method for Mac. you have to get local ip address

enter image description here

Muhammad Hassaan
  • 874
  • 6
  • 18