Thread: need help with HTTP POST

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    need help with HTTP POST

    i want to post a current cookies session to the web server instead of sending the POST login stuff , how do i build the string form what i currently have

    sprintf(body, "vb_login_username=%s&vb_login_password=%s&cookieu ser=1&s=&do=login\r\n", "myuser", "mypass");
    sprintf(headers, "POST /login.php?do=login HTTP/1.0\r\nHost: www.somesite.com\r\n"
    "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: %i\r\n\r\n", strlen(body));

    i am using a firefox addon to get the cookie session , so if i just send that it should not need to ask to login...

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    ive managed to get login to work but cant switch to the index.php page , recv length goes to -1

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    45
    Your posted code seems to be ok, but you should grab (and send) the cookie by yourself.

    What's the exact error code from recv?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    You do realise you can't send data over the same socket again, right?
    To do that, you will need to set keep alive. And even then the server MAY reject this. So it's best to simply reconnect if you don't want to implement the protocol completely.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    Quote Originally Posted by EVOEx View Post
    You do realise you can't send data over the same socket again, right?
    To do that, you will need to set keep alive. And even then the server MAY reject this. So it's best to simply reconnect if you don't want to implement the protocol completely.
    do you mean set keep alive as part of the send string?

    i have tried this

    sprintf(headers, "POST /login.php?do=login HTTP/1.0\r\nHost: www.site.com\r\n"
    "Connection: Keep-Alive\r\n"
    "Content-Type: application/x-www-form-urlencoded\r\n"
    "Content-Length: %i\r\n\r\n", strlen(body));

    after i send this it logs in but after that i a unable to send any GET requests to the main index , it just looks like a lost connection
    Last edited by Anddos; 03-22-2009 at 05:45 AM.

  6. #6
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Quote Originally Posted by EVOEx View Post
    And even then the server MAY reject this. So it's best to simply reconnect if you don't want to implement the protocol completely.
    If adding that doesn't work, then it looks like the server doesn't accept keep-alive requests. You will have to re-open the connection to transfer any other data.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 04-21-2009, 11:04 AM
  2. Post your Best Text Adventure
    By Joe100 in forum Game Programming
    Replies: 3
    Last Post: 08-15-2003, 05:47 PM
  3. Auto POST
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-07-2003, 10:42 AM