2

My test server is iis express, so I can access only localhost:port.

But android emulator's localhost hostname is 10.0.2.2, it occur Bad Request error.

I want change 10.0.2.2 hostname to localhost.

Is it possible? How Can I change it?

js u
  • 71
  • 6
  • 1
    Your question looks like an [X-Y problem](https://xyproblem.info/). – Geno Chen Oct 17 '22 at 06:37
  • `But android emulator's localhost hostname is 10.0.2.2,` No. Not at all. Localhost is localhost and localhost is 127.0.0.1. The 10.0.2.2 has nothing to do with localhost. It is used for connecting to a server that runs on the pc where your emulator is running on too. – blackapps Oct 17 '22 at 06:56
  • `test server is iis express, so I can access only localhost:port.` Sorry, cannot believe that. That would be a useless test server then. – blackapps Oct 17 '22 at 07:01

1 Answers1

0

Android emulator runs in a Virtual Machine and using 10.0.2.2 or 127.0.0.1 or localhost will point to the emulator's own loopback address.

Therefore localhost will not work as a base URL - instead of changing the name you could upgrade to the Url to http://10.0.2.2:8080.

For more info on this you can have a look at this Medium Post. There is also this question on SO which also addresses the same issue.

Tonnie
  • 4,865
  • 3
  • 34
  • 50