1

I am using loopj library for http request, And i am using genymotion for testing. I also want to test on my mobile device but it is showing host unreachable on each ip, whenever i call onclick function on button click.

Here is the Code:

public void onClick(View view) {
            username = emailET.getText().toString();
            password = pwdET.getText().toString();
            AsyncHttpClient client = new AsyncHttpClient();
            RequestParams params = new RequestParams();
            params.put("username", username);
            params.put("password", password);
            client.post("http://10.0.3.2:3000/index", params, new TextHttpResponseHandler() {
                        @Override
                        public void onSuccess(int statusCode, Header[] headers, String res) {
                            try {
                                JSONObject obj = new JSONObject(res);
                                if(obj.getString("success").equals("true")){
                                    Toast.makeText(getApplicationContext(),"Service connected", Toast.LENGTH_LONG);
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                                Toast.makeText(getApplicationContext(),"Server not connected",Toast.LENGTH_LONG);
                            }
                            // called when response HTTP status is "200 OK"
                        }

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

Here are the snippet of node.js and mongodb server running:

node.js

Host unreachable error

user3151301
  • 39
  • 1
  • 8

0 Answers0