I am trying to use HttpURLConnection in my application. I set my request method to "GET", but when I try to get the output stream, the method changes to "POST"! I'm not sure if this is the reason, but my JSON server (I use JAX-RS) returns a blank page when I send a request using "POST".
Here is a snippet of my code:
HttpURLConnection con = (HttpURLConnection) new URL(getUrl() + uriP).openConnection();
if (cookies != null) {
for (String cookie : cookies) {
con.addRequestProperty("Cookie", cookie);
Log.d("JSONServer", "Added cookie: " + cookie);
}
}
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setRequestMethod("GET");
con.setConnectTimeout(20000);
con.addRequestProperty("Accept", "application/json");
OutputStream os = con.getOutputStream();
OutputStreamWriter wr = new OutputStreamWriter(os);
wr.write(requestP);
wr.flush();
Thanks for the answer. Eric
source
share