【问题标题】:Android Async Http ClientAndroid 异步 Http 客户端
【发布时间】:2013-09-01 09:27:24
【问题描述】:

您好,我正在使用 LoopJ 库以 json 格式从服务器获取响应。但问题是有时我得到 org.apache.http.conn.ConnectTimeoutException ,有时它运行良好。我正在使用 GET 方法。但是,当我将 URl 复制并粘贴到我的浏览器时,它运行良好但是在 Android 设备上,我大多无法连接到服务器,这是什么问题。我做错了什么?

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);
        }

    });

【问题讨论】:

标签: android asynchronous loopj


【解决方案1】:

尝试增加您的超时值。 原因是客户端将尝试获得响应,直到超时值。 一旦超过超时值,就会抛出超时异常。

【讨论】:

    猜你喜欢
    • 2016-03-31
    • 2017-12-15
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多