Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java HttpURLConnection.setRequestMethod() doesn't work

i want to change the request methodo from GET to POST. This is my code:

HttpURLConnection connection = null;  

     URL url = new URL("https://accounts.google.com/o/oauth2/token");

     connection = (HttpURLConnection) url.openConnection();
     connection.setRequestMethod("POST");
     connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
     connection.setUseCaches (false);
     connection.setDoInput(true);
     connection.setDoOutput(true);

But as u see in this image while debugging the methodo of the request doesn't change:

enter image description here

like image 821
Ste Avatar asked Jan 23 '15 16:01

Ste


1 Answers

That's just an implementation detail. The HttpsURLConnectionImpl object has a reference to a delegate, and sets that delegate's request method. If you expand the delegate field and check its method field, you'll see POST.

If you follow through with the code, you'll also see it attempts to send a POST request.

like image 77
Sotirios Delimanolis Avatar answered Oct 19 '22 10:10

Sotirios Delimanolis