Post Method in java.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freddieMaize
    New Member
    • Aug 2008
    • 85

    Post Method in java.net

    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);
    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();
    However the results are not as expected. Below is my output,
    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
    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
  • freddieMaize
    New Member
    • Aug 2008
    • 85

    #2
    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

    Comment

    Working...