-1

I know the question has been asked a milion times but I still can't figure out why it is not working. I want to access my asp .net api from my android emulator( android studio) but I always get error 400 hostname invalid. I have looked every topic about it but it is still not working. I have add these three lines

<binding protocol="http" bindingInformation="*:51755:127.0.0.1" /> <binding protocol="http" bindingInformation="*:51755:*" /> <binding protocol="http" bindingInformation="*:51755:172.20.10.9" />

into my C:\Program Files (x86)\IIS Express\config\templates\PersonalWebServer\applicationhost.config but it is still not working.

Here is the code on android studio

AsyncHttpClient client = new AsyncHttpClient();
                RequestParams parameters = new RequestParams();
                parameters.put("userName","test");
                parameters.put("password","test1234");
                parameters.add("confirmPassword","test1234");
                client.post("http://10.0.2.2:51755/api/orders",parameters, new JsonHttpResponseHandler(){
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        // Root JSON in response is an dictionary i.e { "data : [ ... ] }
                        // Handle resulting parsed JSON response here

                        text.setText(response.toString());
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
                        // called when response HTTP status is "4XX" (eg. 401, 403, 404)
                        text.setText(res.toString());
                    }
                });

I cannot figure why it is not working yet, because I followed every thing I found on every topics.

Lucas Tambarin
  • 395
  • 3
  • 14
  • Did you check the binding in IIS? (inetmgr.exe) It may not be registered to accept all hostnames on your port. You post on different ip 10.0.2.2. – vlukham Oct 17 '17 at 16:32
  • I am looking for inetgmr.exe but I can't find it – Lucas Tambarin Oct 17 '17 at 19:32
  • do you have iis installed? type in start -> run -> inetmgr.exe – vlukham Oct 17 '17 at 19:34
  • I don't have the command but I think iis is installed because I have a folder iis and iis express, isn't it? – Lucas Tambarin Oct 17 '17 at 19:39
  • Ok, you are using EXPRESS version, than in order for IIS Express answer on any IP address, just leave the address blank, i.e: bindingInformation=":51755:" – vlukham Oct 17 '17 at 19:50
  • Also IIS Express must run as Administrator to bind to anything but localhost. – vlukham Oct 17 '17 at 19:52
  • This is my connection string in my web api, I am not using iis express right ? – Lucas Tambarin Oct 17 '17 at 20:03
  • This is connection string to database. When you start web api app, you are running under iis express (with debug play button in visual studio), as you have wrote. – vlukham Oct 17 '17 at 20:09
  • Again. one more time: IIS Express starts under Visual Studio in Debug or Release mode, when you click play/start green button. Second: run your Visual Studio under Administrator. Check your bindings at Express version in applicationhost.config as in answer below. Check your routing table to 10.0.2.2 ip. – vlukham Oct 17 '17 at 20:16

1 Answers1

1
  1. In order for IIS Express answer on any IP address, just leave the address blank, i.e: bindingInformation=":51755:"

  2. Also IIS Express must run as Administrator to bind to anything but localhost.

  3. Check your firewall and routing table

vlukham
  • 409
  • 4
  • 11