#32 Submitting form with cookies

closed-works-for-me
None
5
2004-07-25
2004-06-10
wei328
No

Bug:
Form data is omitted by web server when submitting it
together with cookies.

Cause:
When cookies were added to Http headers, the code
added an extra empty line to the header. Web server
sees this empty line as the beginning of the content,
thus skipping the rest of the header.

Fix:
Remove "\r\n" from this line(somewhere near line 773)

$headers .= substr($cookie_headers,0,-2)."\r\n";

becomes
$headers .= substr($cookie_headers,0,-2);

Discussion

  • Gene Wood

    Gene Wood - 2004-07-25

    Logged In: YES
    user_id=547273

    So I've tested this and can't replicate what you're
    experiencing.
    You are right that there is a carriage return after the line
    that adds the cookies into the header, however, there is
    only 1 carriage return. 2 consecutive carriage returns
    designates the end of the header and the beginning of the
    content. All of the headers are added in with a ."\r\n";
    after each to end the line and go to the next.

    I tried doing what you're describing just to make sure I'm
    not overlooking something and it performs as expected. I had
    snoopy post to a form and send cookies at the same time.
    Here is the resulting header (the header that snoopy sends
    to the server). I have put the string ####### immediately
    before and after so the carriage returns can be seen more
    clearly.

    ##########POST /cgi-bin/mt-comments.cgi HTTP/1.0
    User-Agent: (compatible; MSIE 4.01; MSN 2.5; AOL 4.0;
    Windows 98)
    Host: mt.cementhorizon.com
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
    Cookie: test1=238472834723489l; test2=RED
    Pragma: no-cache
    Content-type: application/x-www-form-urlencoded
    Content-length: 91

    ########

    As you can see there are 4 headers that proceed after the
    cookies. If the \r\n were removed from the line like you
    suggest, the header would look like :

    ##########POST /cgi-bin/mt-comments.cgi HTTP/1.0
    User-Agent: (compatible; MSIE 4.01; MSN 2.5; AOL 4.0;
    Windows 98)
    Host: mt.cementhorizon.com
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
    Cookie: lamo=238472834723489l; favoriteColor=REDPragma: no-cache
    Content-type: application/x-www-form-urlencoded
    Content-length: 91

    ########

    Can you provide me with some example code utilizing the
    snoopy class that will exhibit this failure? Can you also
    tell me which version of snoopy you're running?

    Thanks.

     
  • Gene Wood

    Gene Wood - 2004-07-25
    • assigned_to: nobody --> gene_wood
    • status: open --> pending
     
  • Nobody/Anonymous

    Logged In: NO

    Sorry, it's an error on my part.
    I used this loop to find and store the cookies I got from a
    request.

    foreach($http->headers AS $val)
    {
    $cookies = stristr($val,"Set-Cookie");
    if(strlen($cookies) > 0)
    {
    $cookies = substr($cookies,12);
    $cl = explode(";", $cookies);
    foreach($cl AS $clval)
    {
    $c = explode("=", $clval);
    $http->cookies[$c[0]] = $c[1];
    }
    break;
    }
    }

    I forgot to remove "\r\n" from the original cookies header,
    therefore added an extra empty line to the header.

     
  • Gene Wood

    Gene Wood - 2004-07-25
    • status: pending --> closed-works-for-me
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks