Android: "Bad Request-Invalid Hostname" When accessing localhost from emulators

I am not able to use localhost with xamarin.android application. I have executed Web project & Service project(not mobile app) on Chrome Browser.

The displayed port number I tried browsing in Android Studio emulators & Genymotion emulators by appending 10.0.2.2: & 10.0.3.2: respectively, I got result Bad Request-Invalid Hostname. Even I have tried Service project port number, both not working.

Web Project: ASP.NET project using Visual Studio 2017 & Having service project in the same solution.

Open your solution folder. You might have several projects inside 1 folder, you don't need project's folder but the root one. Inside you'd have .vs/config/applicationhost.config file, open it.

find <sites> inside you'll have sites that you are running, might have several, if you switch startup projects in one solution. The name will be corresponding to one displayed by IIS in taskbar when you right-click it's icon. The tag could be, for example, <site name="ServerApp" id="2">. Now you need to add a line to bind external connections to your machine ip, for example

      <site name="ServerApp" id="2">
...
        <bindings>
...
          <binding protocol="http" bindingInformation="*:60424:127.0.0.1" />
        </bindings>
      </site>

Set appropriate port number and protocol, what matters here is just map them to 127.0.0.1, not "localhost" then they will be available for android emulator via 10.0.2.2:60424 (the port number 60424 is just from the example above, use yours)

Phones & Tablets, Simplify your Android development, grow your user base, and monetize more effectively with Google services. Huge Android Smartphone Savings This Season. Up To 50% Off. Android Smartphone First Come First Serve Basis

You can use our free extension Conveyor https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

If the IP that Conveyor gives you doesn't work, just substitute it with 10.0.2.2. Using Conveyor solves the problem of needing to make IIS Express bind to other hostnames. It also has some other features too.

Android Developers, Find My Device makes it easy to locate, ring, or wipe your device from the web. Shop Hundreds of Cases & Accessories Here. We Got Everything You Need. Trusted by millions of customers. Leader in phone accessories. Shop now!

I have solved this issue from third party software ngrock

Check this Android emulator not connecting to localhost api

Android (operating system), Get manufacturer help for your Android device. Samsung help site � LG help site � Motorola help site � Pixel help site � Xiaomi help site � Get help from your device� Special Deals! Compare and Save On Android Phone Now. Biggest Sales Event Here.

Google APIs for Android, You can find your device's Android version number, security update level, and Google Play system level in your Settings app. You'll get notifications when� Over 80% New & Buy It Now; This Is The New eBay. Find Great Deals Now! Fast and Free Shipping On Many Items You Love On eBay.

Android Find My Device, Devices for everything and everyone. Choices for work, gaming, 5G streaming and anything else. There’s over 24,000 phones and tablets that run on Android. So no matter what you’re looking for, there’s something for you.

Android ✓, Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google.

Comments
  • What have you done? You deleted your other post where i tried to help you for hours and just posted your badly worded post again. You are not supposed to behave in that way as you throw away my work too. And then we were not ready yet. Realy terrible.
  • Preceding comments gone to chat section automatically.
  • Then sorry for accusing you. Sorry. Try to undo that as this makes no fun too.
  • What do your bindings look like in IIS?
  • looks like the answer is here: stackoverflow.com/a/15809698/7149454
  • Thank you very much. You save may day