Http get request in Android 2.3.3
android, get, http
Solution
GET request could be used like this:
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://www.google.com";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
// do something with the response
String response = EntityUtils.toString(resEntityGet);
Log.i("GET RESPONSE", response);
}
} catch (Exception e) {
e.printStackTrace();
}
Problem
I need help with sending `HTTP GET` request. My code is as follows: ``` URL connectURL = new URL("url"); HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("GET"); conn.connect(); conn.getOutputStream().flush(); String response = getResponse(conn); ``` But it fails at `getResponse(conn);` Why?