I have an Android app that is trying to execute a GET request to my server using HttpUrlConnection. When I test the code in a separate test desktop application, everything works fine. However, when I run it on my Android device, my server logs a POST request instead of GET.
Here is the code for my method get:
public static String get(String url) throws IOException {
HttpURLConnection conn = connFromUrlString(url);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String out = IOUtils.toString(conn.getInputStream(), "UTF-8");
conn.disconnect();
return out;
}
source
share