Page 1 of 1

Post Data to URL

Posted: Tue Apr 22, 2008 8:25 pm
by rkatl
I have been trying to post data to a URL (https) but no luck. I'm using the following function.

Wondering if anything is wrong in this. Anyone can help ?

function post($data) {

$host = 'www.xxxxxxx.com';
$path = '/test/testform';
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host, 443,$errno, $errstr);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, $data);
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) $http_response .= fgets($fp);
fclose($fp);
echo " hello...< $http_response ...> $data";
echo " ... $errno ... $errstr ...";
return $http_response;
}

Re: Post Data to URL

Posted: Tue Apr 22, 2008 9:33 pm
by Mds
I think this is best way for your purpose :

create HTML form and then submit it . (with javascript and php)

Re: Post Data to URL

Posted: Tue Apr 22, 2008 9:50 pm
by rkatl
not sure what you mean using javascript & php. I have very huge form which I validate and post it using a function.

If you have a sample with javascript could you please share.

Re: Post Data to URL

Posted: Tue Apr 22, 2008 10:06 pm
by John Cartwright
I certainly would not rely on javascript for this. Take a look at cURL, or Snoopy