SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with CURL 411 Length Required

    Hello Masters,

    My curl code is written below, but it results in 411 Length Required.
    Note that I tested with
    PHP Code:
    $hdr[] = "Content-Length: ".$bodyLength."\r\n\r\n"
    but that didnt make any difference, thats why I commented that line off.

    PHP Code:
    $hdr = array();
    $hdr[] = "POST /abc/mypage.aspx HTTP/1.1\r\n";
    $hdr[] = "Host: mysite.com\r\n";
    $hdr[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0\r\n";
    $hdr[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
    $hdr[] = "Accept-Language: en-US,en;q=0.5\r\n";
    $hdr[] = "Accept-Encoding: gzip, deflate\r\n";
    $hdr[] = "Connection: keep-alive\r\n";
    $hdr[] = "Referer: https://www.mysite.com/abc/mypage.aspx\r\n";
    $hdr[] = "Cookie: ASP.NET_SessionId=$ASPSESS\r\n";
    $hdr[] = "Content-Type: multipart/form-data; boundry=".$d.$boundary."\r\n";
    //$hdr[] = "Content-Length: ".$bodyLength."\r\n\r\n";

            
    $ch curl_init();
    curl_setopt($chCURLOPT_POSTTRUE);
    curl_setopt($chCURLOPT_POSTFIELDS$body);
    curl_setopt($chCURLOPT_URL"https://www.mysite.com/abc/mypage.aspx");  
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE); 
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0); 
    curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE); 
    curl_setopt($chCURLOPT_HEADERTRUE); 
    curl_setopt($chCURLOPT_HTTPHEADER$hdr);
    curl_setopt($chCURLOPT_COOKIEFILEdirname(__FILE__) . "/cookies.txt");
    curl_setopt($chCURLOPT_COOKIEJARdirname(__FILE__) . "/cookies.txt");   
    $data curl_exec($ch);
    curl_close($ch); 
    Please help
    Regards
    ZH

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    How are you defining $bodyLength ?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here it is how:

    PHP Code:
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="__VIEWSTATE"'.CRLF.CRLF.$__VIEWSTATE;
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="tbxFirstName"'.CRLF.CRLF.$tbxFirstName;    
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="tbxLastName"'.CRLF.CRLF.$tbxLastName;    
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="tbxAge"'.CRLF.CRLF.$tbxAge;    
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="tbxPatientMRNo"'.CRLF.CRLF.$tbxPatientMRNo;    
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="rlstSex"'.CRLF.CRLF.$rlstSex;    
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="FindFile"; filename=""'.CRLF.$CTOS.CRLF.CRLF;
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="File1"; filename=""'.CRLF.$CTOS.CRLF.CRLF;
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="File2"; filename=""'.CRLF.$CTOS.CRLF.CRLF;
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="File3"; filename=""'.CRLF.$CTOS.CRLF.CRLF;
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="btnSubmit.x"'.CRLF.CRLF."45";
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="btnSubmit.y"'.CRLF.CRLF."7";
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="__EVENTTARGET"'.CRLF.CRLF."";
    $body[] = $d.$boundary.CRLF.'Content-Disposition: form-data; name="__EVENTARGUMENT"'.CRLF.CRLF."";
    $body[] = $d.$boundary."--";
    $bodyString implode(CRLF$body);
    $bodyLength strlen($bodyString); 

  4. #4
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please have a look at the code above.

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Check the request. It *looks* like you're adding duplicate new lines to the headers, the docs (http://www.php.net/manual/en/function.curl-setopt.php) imply you should not add them.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you please locate where is that ?

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,058
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I think he is referring to your \r\n characters in your $hdr declarations.
    PHP Code:
    $hdr[] = "POST /abc/mypage.aspx HTTP/1.1\r\n"
    $hdr[] = "Host: mysite.com\r\n"
    $hdr[] = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0\r\n"
    $hdr[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
    $hdr[] = "Accept-Language: en-US,en;q=0.5\r\n"
    $hdr[] = "Accept-Encoding: gzip, deflate\r\n"
    $hdr[] = "Connection: keep-alive\r\n"
    $hdr[] = "Referer: https://www.mysite.com/abc/mypage.aspx\r\n"
    $hdr[] = "Cookie: ASP.NET_SessionId=$ASPSESS\r\n"
    $hdr[] = "Content-Type: multipart/form-data; boundry=".$d.$boundary."\r\n"
    Try removing ALL of the \r\n in the above section.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •