Re: http request using fsockopen

From: Colin McKinnon (colin.thisisnotmysurname_at_ntlworld.deletemeunlessURaBot.com)
Date: 10/25/04


Date: Mon, 25 Oct 2004 20:59:02 GMT

Rob spilled the following:

>
> I manually create a HTTP request to page C and use the fsockopen method to
> sent the request.
>
> As a result I get the requested page C (status code "200 OK" is returned)
> but the
> POST data is not received/parsed(?). I mean the $_POST array is empty in
> page C. All other PHP scripts in page C is executed as expected though.
>
<snip>
> // headers
> $out ="POST {$path}page_c.php HTTP/1.1 \r\n";
> $out.="Host: $host \r\n";
> $out.="Content-length: ".strlen($query)." \r\n";
> $out.="Content-type: text/html \r\n";

I think you might want to add a:
        Content-type: application/x-www-form-urlencoded
here. Also you should urlencode the RHS of the post variables.

> $out.="Connection: Close \r\n\r\n";

Eh? I don't use this myself and it works for me.

HTH

C.