I'm having problems with POST request and when running on emulator.
Problem with device: When sending POST request I am getting this 411 error (Content-Length required). Adding that request property doesn't help.
Problem with emulator: When typing REST url to web client, it works. But when running it with the application client, I get UnkownHostExpection.
This far I am pretty clueless what to be done to fix my issues, so I was hoping you could point out some tips to solve these.
Thanks.
Here is relevant code:
URL url = new URL("http://etc..");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("Accept", "application/json");
conn.addRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept-Charset", CHARSET_UTF8);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setChunkedStreamingMode(0);
conn.getOutputStream().write(myPostParams.getBytes(CHARSET_UTF8));
conn.connect();
Have you tried setting to use setFixedLengthStreamingMode() instead of setChunkedStreamingMode(0)?
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