java - Can't switch HttpURLConnection method to POST -


i trying send http post request url, using httpsurlconnection. here trying do:

url requestedurl = null; httpurlconnection urlconnection = null;  try {             requestedurl = new url("https://www.test.local/login/");         } catch (malformedurlexception e) {             e.printstacktrace();         }         try {             urlconnection = (httpsurlconnection) requestedurl.openconnection();              try {                 urlconnection.setrequestmethod("post");             } catch (protocolexception e1) {                 e1.printstacktrace();             }             urlconnection.setrequestproperty("content-type","application/json");             urlconnection.setrequestproperty("accept", "application/json");             urlconnection.setdoinput(true);             urlconnection.setdooutput(true);             urlconnection.setusecaches(false);             urlconnection.setconnecttimeout(1500);          try {                 urlconnection.connect();             } catch (ioexception e) {                 e.printstacktrace();             } 

when debugging see requestmethod remains get, idea why?

thanks in advance.

with given code should not able see request @ in network trace.

in given snippet open connection via urlconnection.connect(), not perform actual request urlconnection.getcontent(). connect() method alone not perform request.

replacing last try-catch block following should send post request:

try {     urlconnection.connect(); // open connection     urlconnection.getcontent(); // send prepared request } catch (ioexception e) {     e.printstacktrace(); } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -