How to enter to .aspx page by http connection using http POST request

Discussion in 'Java' started by farazkazmi@gmail.com, Aug 20, 2005.

  1. Guest

    I m facing dificulty with http "POST" request.

    i need to login to a website " https://www.orkut.com "
    it requires username and password.

    i dont know how to enter username and password so that i can access the
    page by myjava class.

    i m using this code gor gettinh request:

    public static String GetRequest() throws IOException {

    String urlString = "https://www.orkut.com";
    DataInputStream dis = null;
    StringBuffer message = new StringBuffer();
    String outputMessage = new String();
    URL url = new URL(urlString);
    HttpURLConnection httpConnection =
    (HttpURLConnection) url.openConnection();
    httpConnection.setRequestMethod("GET");
    httpConnection.setDoInput(true);
    Properties props = System.getProperties();
    props.put("http.proxyHost", "SERVER");
    props.put("http.proxyPort", "8080");
    httpConnection.connect();

    System.out.println(httpConnection.getResponseCode());

    dis = new DataInputStream(httpConnection.getInputStream());
    int ch;
    while ((ch = dis.read()) != -1) {
    message.append((char) ch);
    }
    outputMessage = message.toString();
    //System.out.println(outputMessage);
    httpConnection.disconnect();
    return outputMessage;
    }

    now if i change request method to POST , then plz tell me how can i
    enter username and password by my java code.

    fhkazmi
     
    , Aug 20, 2005
    #1
    1. Advertising

  2. Re: How to enter to .aspx page by http connection using http POSTrequest

    wrote:
    >
    > now if i change request method to POST , then plz tell me how can i
    > enter username and password by my java code.
    >


    Look into the HTTP client library from Apache Jakarta.

    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Aug 20, 2005
    #2
    1. Advertising

  3. writes:

    > i need to login to a website " https://www.orkut.com "
    > it requires username and password.
    >
    > i dont know how to enter username and password so that i can access the
    > page by myjava class.


    If you call

    httpConnection.setAllowUserInteraction(true);

    you should be prompted for username and password if they use BASIC or
    DIGEST HTTP authentication. I don't see anywhere else that you provide
    the username or password.

    If they are parameters but you left them out here, you pass parameters
    in the request body when using POST. Get the output stream and write e.g.

    username=user&password=password

    there. To help the server a little, you should also set the
    Content-Length request field to the length of that body.
     
    Tor Iver Wilhelmsen, Aug 20, 2005
    #3
  4. Guest


    > If you call
    >
    > httpConnection.setAllowUserInteraction(true);
    >
    > you should be prompted for username and password if they use BASIC or
    > DIGEST HTTP authentication. I don't see anywhere else that you provide
    > the username or password.
    >
    > If they are parameters but you left them out here, you pass parameters
    > in the request body when using POST. Get the output stream and write e.g.
    >
    > username=user&password=password
    >

    ...
    After some research i found that, i can also login by this url through
    browser.
    https://www.orkut.com/Login.aspx?&u=username&p=password.

    i tried allow user interaction but it didnt work.

    also m confused about the Content Length , if it is
    String info = u=username&p=password then
    httpConnection.setRequestproperty("CONTENT-LENGTH","info.Length()");

    is it right?.

    plz tell me ,
    i tried with the above link with username and password but it retrs the
    same URL page.

    any idea?

    plz tell me..
     
    , Aug 20, 2005
    #4
  5. Guest

    i found 1 problem that the returend page has the follwing message
    " Please enable cookies in your browser to login to orkut"

    plz tell me how can i deal with this problem
     
    , Aug 20, 2005
    #5
  6. writes:

    > plz tell me how can i deal with this problem


    You need to detect (keep) the Set-Cookie header value you get in the
    response when logging in, and send it back on every further request.
    Do a Google search for the HTTP cookie spec.
     
    Tor Iver Wilhelmsen, Aug 29, 2005
    #6
  7. writes:

    > httpConnection.setRequestproperty("CONTENT-LENGTH","info.Length()");


    Almost:

    httpConnection.setRequestproperty("CONTENT-LENGTH",String.valueOf(info.length()));

    And you only do this if you use a POST type request - you apparently
    use a GET since you pass the parameters in the URL.
     
    Tor Iver Wilhelmsen, Aug 29, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sriram Mallajyosula

    How do I post data from aspx page to another aspx page.

    Sriram Mallajyosula, Nov 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,065
    Steve C. Orr [MVP, MCSD]
    Nov 5, 2003
  2. Ricardo Magalhaes
    Replies:
    0
    Views:
    849
    Ricardo Magalhaes
    Jun 3, 2005
  3. James
    Replies:
    3
    Views:
    16,640
    Roedy Green
    Nov 25, 2005
  4. Replies:
    3
    Views:
    846
    Guillermo
    Apr 26, 2007
  5. HopfZ
    Replies:
    0
    Views:
    629
    HopfZ
    Aug 28, 2006
Loading...

Share This Page