Android - erro ao tentar conectar-se ao servidor local (Xampp)
aqui está o meu logcat e a primeira linha do URL que eu tento conectar e é válido
ela é o meu código que causa o erro e faz a conexão recusar
public static String makeHttpRequest(URL url) throws IOException {
String jsonResponse = "";
Log.e(LOG_TAG, url.toString());
// If the URL is null, then return early.
if (url == null) {
return jsonResponse;
}
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(LOG_TAG, "Error response code: " + urlConnection.getResponseCode());
}
} catch (IOException e) {
Log.e(LOG_TAG, "Problem retrieving the Category JSON results.", e);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (inputStream != null) {
inputStream.close();
}
}
return jsonResponse;
}
Eu já sei como fazer o HTTP conectar e fiz isso muito antes, mas esta é a primeira vez no servidor local