使用应用程式的android地震应用程式

时间:2018-07-03 16:58:17

标签: android

好,所以我开发了一个地震api应用程序,并且可以正常工作。现在我已经开始怀疑我了。我使用了HTTP请求方法来请求服务器请求并使用json响应。但是我找不到我的代码中任何端口号的用法。应该有一些使用端口号不正确的tcp连接。这是由android ide本身处理的。我已附加了该方法中使用的代码。任何人都可以帮帮我

HttpURLConnection urlConnection = null;
        InputStream inputStream = null;
        try {
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setReadTimeout(10000 /* milliseconds */);
            urlConnection.setConnectTimeout(15000 /* milliseconds */);
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();.

            // If the request was successful (response code 200),
            // then read the input stream and parse the response.
            if (urlConnection.getResponseCode() == 200) {
                inputStream = urlConnection.getInputStream();
                jsonResponse = readFromStream(inputStream);
            } else {
 Log.e(SAMPLE_JSON_RESPONSE, "Error response code: " + urlConnection.getResponseCode());
            }
        } catch (IOException e) {
            Log.e(SAMPLE_JSON_RESPONSE, "Problem retrieving the earthquake JSON results.", e);
        }
        finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
            if (inputStream != null) {
                // Closing the input stream could throw an IOException, which is why
                // the makeHttpRequest(URL url) method signature specifies than an IOException
                // could be thrown.
                inputStream.close();
            }
        }
        return jsonResponse;
    }

0 个答案:

没有答案