Here's my predicament. I Have managed to send and retrieve some HTTP requests using the GET method successfully using the following code:

function send_to_host($host,$method,$path='/',$data='',$useragent=0){
    // Supply a default method of GET if the one passed was empty
    if (empty($method)) {
        $method = 'GET';
    }
    $method = strtoupper($method);
    $fp = fsockopen($host, 80) or die("Unable to open socket");
	
    fputs($fp, "$method $path HTTP/1.1\r\n");
    fputs($fp, "Host: $host\r\n");
    fputs($fp, "Content-type: application/x-www-form- urlencoded\r\n");
    if ($method == 'POST') fputs($fp, "Content-length: " . strlen($data) . "\r\n");
    if ($useragent) fputs($fp, "User-Agent: MSIE\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    if ($method == 'POST') fputs($fp, $data);

    while (!feof($fp))
		$buf .= fgets($fp,128);
	
    fclose($fp);
    return $buf;
}

send_to_host('humbot.freewebhostingpro.com','GET','/index.php?a=5','');
//sent from localhost

I have tried a few times to send some data via POST but haven't had any luck. (I haven't had any trace of the POST data getting through)

(set up a form to submit some GET and POST data to humbot.freewebhostingpro.com/index.php and the page will display that data)

Any ideas?

you are passing only three parameters. For post, your third parameter should be only the php script that processes the request(without the querystring parameters) and the fourth parameter should be the "querystring" data. Try:

send_to_host('humbot.freewebhostingpro.com','POST','/index.php','a=5');

Notice how line 24 of my code includes "GET" and not "POST"? That's the call I used to (successfully) send a GET request (as the English above clearly states).

I have slightly modified the code making up that function from the code I got off the net so I understand what needs to go in which parameter.

I have tried the line you suggested an a few similar (even with the original code) but none have shown me that my POST data was received.

>>Notice how line 24 of my code includes "GET" and not "POST"? That's the call I used to (successfully) send a GET request (as the English above clearly states).
Yes, I can see that, but it is NOT clear if you were doing this:

send_to_host('humbot.freewebhostingpro.com','POST','/index.php?a=5','');

which is NOT the correct way to call it. The parameters should not be appended to the uri. Instead you need:

send_to_host('humbot.freewebhostingpro.com','POST','/index.php','a=5');

On another note, the source of the problem is:

fputs($fp, "Content-type: application/x-www-form- urlencoded\r\n");

there should be NO space between the hyphen and urlencoded. It should be:

fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
Comments
That last bit of info was my problem. Cheers

Thanks for that last bit of info, it has actually made my requests successful. You've been a big help because HTTP headers is something I have only briefly read over.

Cheers.

nice Job on that solution. i was putzing around with this same piece of code and didn't see that either, thanks.

>>i was putzing around with this same piece of code and didn't see that either
out of curiosity, where did you guys get that code from?

>>thanks.
you are welcome.

humbug, thanks for the reply. Hopefully icandothat can shed some light on the source of pertaining code. Take care.

This question has already been answered. Start a new discussion instead.