Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的android应用程序在浏览器仍然可以使用时连接超时_Java_Android - Fatal编程技术网

Java 我的android应用程序在浏览器仍然可以使用时连接超时

Java 我的android应用程序在浏览器仍然可以使用时连接超时,java,android,Java,Android,代码: public static String openUrl(String url, String method, RequestParam params) throws NuageException { HttpURLConnection conn = null; String response = ""; String decodParam = params.decod(); if (metho

代码:

   public static String openUrl(String url, String method,
            RequestParam params) throws NuageException {
        HttpURLConnection conn = null;
        String response = "";
        String decodParam = params.decod();
        if (method.equals(GET)) 
            {
            url = url + "?" + decodParam;
            // Log.v(LOG_TAG, "GET:" + url);
        }

         try {
            Log.v("开始请求:", String.valueOf(System.currentTimeMillis()));
            conn = (HttpURLConnection) new URL(url).openConnection();
            conn.setReadTimeout(READTIMEOUT);
            conn.setConnectTimeout(CONNECTTIMEOUT);
            conn.setUseCaches(false);
            conn.setRequestProperty("Connection", "Keep-Alive");
            if (method.equals(POST)) {
                conn.setRequestMethod("POST");
                conn.setDoOutput(true);
                conn.getOutputStream().write(decodParam.getBytes("UTF-8"));
                // Log.v(LOG_TAG, "POST:" + url + " " + decodParam);
            }
            InputStream is = null;
            conn.connect();
            int responseCode = conn.getResponseCode();
            if (responseCode == 200 || responseCode == 201
                    || responseCode == 202) {
                is = conn.getInputStream();
            } else {
                is = conn.getErrorStream();
            }
            response = read(is);
            Log.v("请求结束:", String.valueOf(System.currentTimeMillis()));
            Log.v(LOG_TAG, "response:" + response);
            checkResponse(response);
        } catch (MalformedURLException e) {
            throw new NuageException(e);
        } catch (IOException e) {
            if (e.getMessage() != null && e.getMessage().equals(
                    "Received authentication challenge is null"))
                throw new NuageException(new NuageError(
                        NuageError.ERROR_SESSIONKEY_INVALID, "", "", ""));
            e.printStackTrace();
            throw new NuageException(e);
        } catch (NuageException e) {
            throw e;
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return response;
    }
有时我会看到
java.net.SocketTimeoutException:当浏览器仍然工作时,连接超时


有人能帮我改进代码吗?

什么是URL?您是在它前面加了http还是https?您的超时是什么(CONNECTTIMEOUT、READTIMEOUT)。我假设你以为它是以秒为单位的,但它是以毫秒为单位的……它是300000和60000,我认为它很长。嗨,丹尼斯,你找到解决办法了吗?