I\'m trying to use HttpURLClient to send some POST data to a server using the HttpRestClient
class shown below. When executing
conn.setDoInput(true)
You called both of conn.setDoInput(true);
and conn.setDoOutput(true);
. Use one of them:
setDoOutput(true)
is used for POST
and PUT
requests.setDoInput(true)
is used for GET
request.The connection you made was confused, it can't decide which request should be used.
In your code:
static public int post(String urlStr, List data){
HttpURLConnection conn = null;
System.setProperty("http.keepAlive", "false"); // must be set
try {
...
conn.setDoOutput(true);
conn.setRequestMethod("POST");
// and connect to server, if needed
conn.connect();
...
}
....