I am getting 'connection refused' or 'bad request' when trying to connect from the android emulator to my web service on localhost. I have added the port number to the firewall to allow connections, and I have tried the advice given here to modify applicationhost.config
Both the web service and the emulator are running on the same (Windows 10) PC. In the server's web.config I have the following under 'system.webserver':
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST" />
using (WebClient client = new WebClient())
string json = ......;
client.Headers[HttpRequestHeader.ContentType] = "application/json";
// I have also tried "application/x-www-form-urlencoded";
string result = client.UploadString(UrlBase.urlBase + "SaveLocation", json);
I am not using any firewall rules because my emulator is on the same machine as the service host. As Jason said you should use your host IP address. To avoid many problems use local IIS host not IIS express. Your "Bad request" is not invalid Json but Invalid host name because IIS express will not allow ANY connections but from the local machine. You can try to trick it as in the link you referenced above but why bother?
This is the result of IIS Express hosted app.
This is the result of local IIS hosted app
After getting the project here is the result: