Expand|Select|Wrap|Line Numbers
- String username = "Freddiemaize";
- String password = "*******";
- String loginDetails = "user_login="+ username +"&user_pass=" + password;
Expand|Select|Wrap|Line Numbers
- URL wordpressLogin = new URL( " http://freddiemaize.wordpress.com/wp-login.php /" );
- HttpURLConnection HTTP = ( HttpURLConnection ) wordpressLogin.openConnection();
Expand|Select|Wrap|Line Numbers
- HTTP.setRequestMethod( "POST" );
- HTTP.setRequestProperty( "Content-Length", "" + Integer.toString(loginDetails.getBytes().length ) );
- HTTP.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
Expand|Select|Wrap|Line Numbers
- DataOutputStream printOut = new DataOutputStream( HTTP.getOutputStream() );
- printOut.writeBytes(loginDetails);
Expand|Select|Wrap|Line Numbers
- 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();
getRequestMethod - GETWell, 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.
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