I’m using a POST method in java.net. Below are my code snippets.
Code:
String username = "Freddiemaize";
String password = "*******";
String loginDetails = "user_login="+ username +"&user_pass=" + password;
Code:
URL wordpressLogin = new URL( " http://freddiemaize.wordpress.com/wp-login.php /" );
HttpURLConnection HTTP = ( HttpURLConnection ) wordpressLogin.openConnection();
Code:
HTTP.setRequestMethod( "POST" );
HTTP.setRequestProperty( "Content-Length", "" + Integer.toString(loginDetails.getBytes().length ) );
HTTP.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
Code:
DataOutputStream printOut = new DataOutputStream( HTTP.getOutputStream() );
printOut.writeBytes(loginDetails);
However the results are not as expected. Below is my output,Code:
System.out.println("getHeaderFields - "+HTTP.getHeaderFields().toString());
System.out.println("getRequestMethod - "+HTTP.getRequestMethod());
System.out.println("getRequestMethod - "+HTTP.getResponseCode());
System.out.println("getURL - "+HTTP.getURL().toString());
in.close();
Well, I expect a 302 response code and the method to be POST and the url to be http*://freddiemaize.wordpress.com/wp-admin/ which is my landing page.Quote:
getRequestMethod - GET
getRequestMethod - 200
getURL - http*://freddiemaize.wordpress.com/wp-login.php?action=auth&redirect_to=
http%3A%2F%2Ffreddiemaize.wordpress.com%2Fwp-admin%2F
My doubt is, is my expectation wrong or my expectation is correct but there is a bug in my code. Please advice. Thank you very much.
Freddie
