I’m using a POST method in java.net. Below are my code snippets.
However the results are not as expected. Below is my output,
Well, I expect a 302 response code and the method to be POST and the url to be http*://freddiemaize.wo rdpress.com/wp-admin/ which is my landing page.
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
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);
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();
getRequestMetho d - GET
getRequestMetho d - 200
getURL - http*://freddiemaize.wo rdpress.com/wp-login.php?actio n=auth&redirect _to=
http%3A%2F%2Ffr eddiemaize.word press.com%2Fwp-admin%2F
getRequestMetho d - 200
getURL - http*://freddiemaize.wo rdpress.com/wp-login.php?actio n=auth&redirect _to=
http%3A%2F%2Ffr eddiemaize.word press.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
Comment