I've got an Android app that's trying to do a GET request to my server using HttpUrlConnection. When I test the code in a separate testing desktop application, everything works fine. However, when I run it on my android device, my server registers a POST request instead of a GET.
Here's the code for my get
method:
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;
}
This line is the culprit.
conn.setDoOutput(true);
Remove that and give it a try.
By the way, you should read this excellent piece: https://stackoverflow.com/a/2793153/415412
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With