By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,375 Members | 1,426 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,375 IT Pros & Developers. It's quick & easy.

Post Method in java.net

freddieMaize
P: 85
I’m using a POST method in java.net. Below are my code snippets.

Expand|Select|Wrap|Line Numbers
  1. String username = "Freddiemaize";
  2. String password = "*******";
  3. String loginDetails = "user_login="+ username +"&user_pass=" + password;
Expand|Select|Wrap|Line Numbers
  1. URL wordpressLogin = new URL( " http://freddiemaize.wordpress.com/wp-login.php /" );
  2. HttpURLConnection HTTP = ( HttpURLConnection ) wordpressLogin.openConnection();
Expand|Select|Wrap|Line Numbers
  1. HTTP.setRequestMethod( "POST" );
  2. HTTP.setRequestProperty( "Content-Length", "" + Integer.toString(loginDetails.getBytes().length ) );
  3. HTTP.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
Expand|Select|Wrap|Line Numbers
  1. DataOutputStream printOut = new DataOutputStream( HTTP.getOutputStream() );
  2. printOut.writeBytes(loginDetails);
Expand|Select|Wrap|Line Numbers
  1. System.out.println("getHeaderFields - "+HTTP.getHeaderFields().toString());
  2. System.out.println("getRequestMethod - "+HTTP.getRequestMethod());
  3. System.out.println("getRequestMethod - "+HTTP.getResponseCode());
  4. System.out.println("getURL - "+HTTP.getURL().toString());
  5. in.close();
However the results are not as expected. Below is my output,
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
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.

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
Dec 19 '08 #1
Share this Question
Share on Google+
1 Reply


freddieMaize
P: 85
Or atleast any suggestions on what response code would be returned if we ask for a login page via POST method. 200 or a 302 ? generally?

fREDDIE
Dec 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.