0

Hi i am using LoopJ lib to get response from server in json. But the problem is that at times i get org.apache.http.conn.ConnectTimeoutException and sometimes it runs fine. I am using the GET method. But when ever i copy and paste the URl to my Browser it runs fine But on the Android device i mostly cant connect to the server what is the problem. What am i doing wrong ?

client.setTimeout(timoutVal);
client.get(
    "http://somewebsiteaddress.com/users.php?task=isUserPresent&email="
        + URLEncoder.encode(username) + "&password="
        + URLEncoder.encode(password) + "&licenseKey="
        + URLEncoder.encode(licKey), null,
    new AsyncHttpResponseHandler() {

        public void onSuccess(String response) {

        loading.cancel();

        Log.v("web response ", response);

        try {
            json = new JSONObject(response);

            if (json.getBoolean("status")) {

            delegate.Validation(
                json.getBoolean("isUserPresent"),

                json.getBoolean("license"), username,
                password, json);

            } else {

            delegate.invalidLogin();
            }

        } catch (JSONException e) {

            e.printStackTrace();
        }

        }

        @Override
        public void onFailure(Throwable arg) {

        Log.v("onFailure", arg + "");

        loading.cancel();

        delegate.InternetErrorDialog();

        super.onFailure(arg);
        }

    });
Hasham
  • 455
  • 4
  • 11
  • Just mentioning the reason : http://developer.android.com/reference/org/apache/http/conn/ConnectTimeoutException.html Might be because of `timeout while connecting to an HTTP server or waiting for an available connection`. – Shobhit Puri Sep 01 '13 at 09:33

1 Answers1

0

Try to increase your timeout value. The reason is client will try to get response until timeout value. As soon as it exceeds the timeout value it will throw timeout exception.

Meenaxi
  • 567
  • 5
  • 17