4

I am building a website, and I would like to see how it is rendered on an Android Smartphone, so I downloaded Genymotion. I can't see any pages on my local site from Genymotion ("Bad request - invalid hostname").

When I launch the Visual Studio solution, the homepage address is

http://localhost:18207

so following the advice that I found for example here I typed in Genymotion the following addresses:

http://10.0.3.2:18207

http://192.168.56.1:18207

http://(my ip address):18207

but I always have the above mentioned error, or sometimes a timeout error.

Thanks a lot for any suggestion!

Community
  • 1
  • 1
Sean
  • 923
  • 3
  • 14
  • 36

4 Answers4

6

I ran into this exact same issue and resovled it with the help of this blog post:

http://blog.binarybits.net/applications/iis-express-http-error-400-the-request-hostname-is-invalid/

I don't want to take any credit for the content of that post, but just in case it goes offline I'll lay out the process. Essentially you need to update the configuration for IIS Express so it'll accept the incoming request from Genymotion. So assuming that your site is running on port 8080:

Step 1 - Modify the specific configuration for your site in C:\Users\\Documents\IISExpress\config\applicationhost.config so it's tied to * instead of localhost

<site name="WebSite1" id="1" serverAutoStart="true">
 <application path="/">
  <virtualDirectory path="/" physicalPath="PATH TO YOUR SITE" />
 </application>
 <bindings>
  <binding protocol="http" bindingInformation=":8080:*" /> <!-- CHANGE THIS LINE -->
 </bindings>
</site>

Step 2 - Add an ACL rule to let incoming connections access your laptop on this (run this command via admin)

netsh http add urlacl url=http://*:8080/ user=everyone

Step 3 - Finally connect to your site within Genymotion using this special address

http://10.0.3.2:8080/

That worked for me, so hopefully it works for you as well.

Sam Storie
  • 4,444
  • 4
  • 48
  • 74
  • After hours of digging around this finally works. I was calling a IIS Express WCF Web Service rather than a website and this solved my issue. I just have to make sure that I don't switch the emulator in future because 10.0.2.3 is unique to Genymotion's localhost address. – nishantvodoo Jul 02 '15 at 17:19
  • There are applicationhost.config files everywhere... To find the right one, right click the IIS-icon and select "Show all applications". Highlight the application in the list, and it will display the path to the right config file – Kristoffer Berge Apr 20 '18 at 10:09
1

In my case, a slight modification in the answer provided by Sam Storie solved the problem. My local service is hosted using MVC Web Api controllers (I'm using Visual Studio 2013).

In step 1, instead of replacing :8080:localhost to :8080:*, I just added a new binding right next to the existing one. The new binding does not have either localhost or * in it. It will look like this:

 <bindings>
  <binding protocol="http" bindingInformation=":8080:localhost" /> <!-- Existing binding -->
  <binding protocol="http" bindingInformation=":8080:" /> <!-- New binding. Note that there is no asterisk(*)--> 
 </bindings>

Just in case it is not clear, ensure that you replace 8080 with the actual port where the service is hosted on localhost. In my case it is 53533.

user3655614
  • 56
  • 1
  • 6
0

Run your web server on the 192.168.56.1 net. This is usually a setting in the server config. It's probably defaulting to the real adapter of your host, not the virtual adapter that VirtualBox is connected to. I'm not sure what host OS you're on, but the virtual adapter is usually vbox0 for a Linux install. This is the virtual network that Genymotion is on.

Your Genymotion VM will have a DHCP address like 192.168.56.101. You can check for sure with the Genymotion config app inside the VM. If this is the case, and your web server is also on this subnet, you should be able to point your Genymotion browser to 192.168.56.1.

Paul Ratazzi
  • 6,289
  • 3
  • 38
  • 50
  • I am on Windows 8. I already tried the address that you mention, as described in my question, but without success. In ipconfig I have that address under "Ethernet adapter VirtualBox Host-Only Network". – Sean Jul 28 '14 at 07:47
  • Can you successfully ping the Windows host (192.168.56.1) from inside the Android VM (i.e., `adb shell ping 192.168.56.1`)? Also, have you checked to see if your Windows firewall is causing the problem? My setup does what you want but is on Linux, otherwise I would be more specific. – Paul Ratazzi Jul 28 '14 at 16:33
  • Also, did you confirm that the web server is actually listening on 192.168.56.1? If it is, that address should also work from your Windows browser. Do any server addresses besides `locahost` work from Windows? – Paul Ratazzi Jul 28 '14 at 16:34
  • Effectively, if I put in the browser the address http://192.168.56.1 it does not work. Could you tell me how to ping in Android? I didn't find the "adb shell". Thank you. – Sean Jul 29 '14 at 07:19
  • My bad for assuming you had the SDK and adb installed. To test connectivity from inside your Genymotion device, boot it up, download a terminal emulator like this: https://github.com/jackpal/Android-Terminal-Emulator/wiki, and install the APK by dragging and dropping it on top of the running Genymotion device. It will run and give you a Linux shell. Type `ping 192.168.56.1` and you should get a list showing response times in milliseconds. – Paul Ratazzi Jul 29 '14 at 13:23
  • You should be able to do the same in reverse from a Windows command tool. Open one up (as admin) and type `ping 192.168.56.101` or whatever the address of your Genymotion VM is. You can check that using the Genymotion Configuration app that is available in the Genymotion VM. – Paul Ratazzi Jul 29 '14 at 13:25
  • Finally, in regards to `192.168.56.1` not working, you keep mentioning the browser, but have you checked your localhost _server_ configuration to make sure it's listening to the VirtualBox host only network? You have to do that for any of this to work. It has nothing to do with the browser - it's in the server configuration. `localhost` is not going to visible at all from inside the VM. – Paul Ratazzi Jul 29 '14 at 13:27
  • I tried the ping in the terminal emulator, even with the firewall off, the reply is: "icmp open socket: operation not permitted". The same ping works in the Windows command prompt. In the server configuration I see that it is listening to the port mentioned in my question: – Sean Jul 30 '14 at 08:41
  • I'm afraid I'm running out of ideas. You have to get the ping from inside the VM to work before you'll have any hope of getting the Android browser to load a page from your PC's server. So keep working on that. The error you show above looks like some kind of security problem - maybe try typing `su` in the emulator before running it. – Paul Ratazzi Jul 30 '14 at 13:18
  • Regarding your server config line above: it's not with the port that I see a problem, it's with the `localhost` part. Change that to the address of your VBox host-only adapter (something like `192.168.56.1`). But like I said above, the ping needs to work before you can conclude that there is a problem with the web service. – Paul Ratazzi Jul 30 '14 at 13:21
  • Sorry I don't have more for you. I have this exact same thing working here on my Linux box, so I'm sure it can be done. Keep trying. – Paul Ratazzi Jul 30 '14 at 13:22
  • I typed "su" and after this the ping worked, but in the browser always the same problem....thank you very much anyway. – Sean Jul 30 '14 at 14:10
0

You just need to use http://yourHostIpAdress/YourWebSite (no need of port)

At least this worked when publishing the website locally through IIS

Ed_
  • 973
  • 11
  • 25