Connecting Tech Pros Worldwide Forums | Help | Site Map

getting bad results from fsocketopen

lawrence k
Guest
 
Posts: n/a
#1: May 12 '06
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


yawnmoth
Guest
 
Posts: n/a
#2: May 12 '06

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...

lawrence k
Guest
 
Posts: n/a
#3: May 12 '06

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.

lawrence k
Guest
 
Posts: n/a
#4: May 12 '06

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?

yawnmoth
Guest
 
Posts: n/a
#5: May 12 '06

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.

lawrence k
Guest
 
Posts: n/a
#6: May 12 '06

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.

Closed Thread