Connecting Tech Pros Worldwide Help | Site Map

getting bad results from fsocketopen

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 12th, 2006, 02:55 AM
lawrence k
Guest
 
Posts: n/a
Default getting bad results from fsocketopen

If I send this to the server:

POST /errors/index.htm HTTP/1.1
Host: www.publicdomainsoftware.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 1200
%3C%2Fdiv%3E



Why do I get this back:

HTTP/1.1 400 Bad Request Date: Fri, 12 May 2006 02:37:43 GMT Server:
Apache/2.0.46 (Red Hat) Content-Length: 302 Connection: close
Content-Type: text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.0.46 (Red Hat) Server at default Port 80


  #2  
Old May 12th, 2006, 03:15 AM
yawnmoth
Guest
 
Posts: n/a
Default Re: getting bad results from fsocketopen

lawrence k wrote:[color=blue]
> If I send this to the server:
>
> POST /errors/index.htm HTTP/1.1
> Host: www.publicdomainsoftware.org
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 1200
> %3C%2Fdiv%3E[/color]

Try this, instead:

POST /errors/index.htm HTTP/1.1
Host: www.publicdomainsoftware.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 1200
Connection: close

%3C%2Fdiv%3E

Note how there are two new lines between the last HTTP header and the
actual data. Also... the Content-Length field doesn't look correct.
strlen(urldecode('%3C%2Fdiv%3E')) is definitly not 1200...

  #3  
Old May 12th, 2006, 04:25 AM
lawrence k
Guest
 
Posts: n/a
Default Re: getting bad results from fsocketopen


yawnmoth wrote:[color=blue]
> Try this, instead:
>
> POST /errors/index.htm HTTP/1.1
> Host: www.publicdomainsoftware.org
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 1200
> Connection: close
>
> %3C%2Fdiv%3E
>
> Note how there are two new lines between the last HTTP header and the
> actual data. Also... the Content-Length field doesn't look correct.
> strlen(urldecode('%3C%2Fdiv%3E')) is definitly not 1200...[/color]

Thanks much. That did the trick.

  #4  
Old May 12th, 2006, 05:15 AM
lawrence k
Guest
 
Posts: n/a
Default Re: getting bad results from fsocketopen


yawnmoth wrote:[color=blue]
> Try this, instead:
>
> POST /errors/index.htm HTTP/1.1
> Host: www.publicdomainsoftware.org
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 1200
> Connection: close
>
> %3C%2Fdiv%3E
>
> Note how there are two new lines between the last HTTP header and the
> actual data. Also... the Content-Length field doesn't look correct.
> strlen(urldecode('%3C%2Fdiv%3E')) is definitly not 1200...[/color]


It's curious, but fsocketopen takes forever. It's basically unuseable
for me. It brings the site to a standstill. My code is taken straight
from an example on www.php.net:



$message = rawurlencode($message);
$message = "&errorInput=$message";
$length = strlen($message);

$fp = fsockopen("www.publicdomainsoftware.org", 80, $errno, $errstr,
30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "POST /errors/errorInput.php HTTP/1.1\r\n";
$out .= "Host: www.publicdomainsoftware.org\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: $length\r\n";
$out .= "Connection: Close\r\n\r\n";
$out .= "$message";

fwrite($fp, $out);
while (!feof($fp)) {
// echo fgets($fp, 128);
}
fclose($fp);
}



The variable $message is just the parameter being passed in. This code
can take 4 or 5 minutes to work, and then finally the pages, often,
just time out.

Any idea why that might be?

  #5  
Old May 12th, 2006, 05:35 AM
yawnmoth
Guest
 
Posts: n/a
Default Re: getting bad results from fsocketopen


lawrence k wrote:[color=blue]
> <snip>
> It's curious, but fsocketopen takes forever. It's basically unuseable
> for me. It brings the site to a standstill. My code is taken straight
> from an example on www.php.net:
>
> <snip>
>
> while (!feof($fp)) {
> // echo fgets($fp, 128);
> }
> fclose($fp);
> }
>[/color]
The file pointer never gets to the end of the file because its never
incremented. As such, try uncommenting out the fgets.

  #6  
Old May 12th, 2006, 08:55 AM
lawrence k
Guest
 
Posts: n/a
Default Re: getting bad results from fsocketopen


yawnmoth wrote:[color=blue]
> lawrence k wrote:[color=green]
> > <snip>
> > It's curious, but fsocketopen takes forever. It's basically unuseable
> > for me. It brings the site to a standstill. My code is taken straight
> > from an example on www.php.net:
> >
> > <snip>
> >
> > while (!feof($fp)) {
> > // echo fgets($fp, 128);
> > }
> > fclose($fp);
> > }
> >[/color]
> The file pointer never gets to the end of the file because its never
> incremented. As such, try uncommenting out the fgets.[/color]

Thanks a million for catching that. You saved the day again.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.