SitePoint Sponsor

User Tag List

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

    PHP fsockopen returns Bad Header (Invalid Header Name)

    Hi

    This is the header that my PHP script sends via fsockopen

    HTML Code:
    POST /xyz/add.aspx HTTP/1.0
    Host: mywebsite.com
    User-Agent=Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
    Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language=en-US,en;q=0.5
    Accept-Encoding=gzip, deflate
    Connection=keep-alive
    Referer=https://www.mywebsite.com/xyz/add.aspx
    Cookie=ASP.NET_SessionId=12345678910101010
    Content-Type=multipart/form-data
    
    Content-Length=17053
    But it returns:
    Bad Header (Invalid Header Name)

    I have to do it without cURL

    Please tell me what is wrong ?

    Million Thanks
    ZH

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You have white space between Content-Type and Content-Length which should not be there.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks for your reply.

    I just removed the blank line, but the result stays the same.

  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 help ! so much views and no one replied apart from just 1 ?

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You are using = instead of : in several of your headers which isn't allowed (based on what I see at fsocketopen)

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

    Thanks YES, I already fixed that and also added POSTDATA: etc. That thing worked now.

    But, now, the new issue is : I get this message:

    <br />
    <b>Warning</b>: fgets(): SSL: The operation completed successfully.


    Please Help !

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Post your code, as I can't tell you what that means without seeing it.

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

    PHP Code:
    $headers "POST /abc/add.aspx HTTP/1.1\r\n";
    $headers .= "Host: mysite.com\r\n";
    $headers .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0\r\n";
    $headers .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
    $headers .= "Accept-Language: en-US,en;q=0.5\r\n";
    $headers .= "Accept-Encoding: gzip, deflate\r\n";
    $headers .= "Connection: keep-alive\r\n";
    $headers .= "Referer: https://www.mysite.com/abc/add.aspx\r\n";
    $headers .= "Cookie: ASP.NET_SessionId=$ASPSESS\r\n";
    $headers .= "Content-Type: multipart/form-data; boundry=".$d.$boundary."\r\n";
    $headers .= "Content-Length: $bodyLength\r\n";
    $headers .= "POSTDATA: $bodyString";
                
    $fp fsockopen("ssl://www.mysite.com"443$errno$errstr);
    if (
    $fp)
    {
        
    fwrite($fp$headers);
        
    $response '';
        while (!
    feof($fp))
             
    $response .= fgets($fp);
        
    fclose($fp);


  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    What version of PHP are you running this on? A google search I ran seems to indicate this is an issue with lower versions of PHP 4, or any version of PHP that isn't compiled with the openssl option. I'm not 100% certain yet which may be your case, or if there is another reason for this warning to be generated.

  10. #10
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have latest PHP version with OPENSSL installed. If openssl is not installed it shows other error message, not the one i posted.


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
  •