Tach zusammen...
ich versuche schon seit ein paar stunden mir was zusammen zu basteln was es mir ermoeglicht in PHP einen https POST request zu senden und anschliessend die ausgabe des servers zu empfangen und zu verarbeiten. Ich bin dabei ueber folgendes script gestolpert:
//-----------------------------------------------------------------------
$host = "somehost.somedomain.com";
$port = 443;
$path = "/the/url/path/file.php"; //or .dll, etc. for authnet, etc.
//you will need to setup an array of fields to post with
//then create the post string
$formdata = array ( "x_field" => "somevalue");
//build the post string
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 30);
if(!$fp){
//error tell us
echo "$errstr ($errno)\n";
}else{
//send the server request
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: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
//loop through the response from the server
while(!feof($fp)) {
echo fgets($fp, 4096);
}
//close fp - we are done with it
fclose($fp);
}
//-----------------------------------------------------------------------
Leider ist alles was ich bekomme ein unexpected T_FOREACH error in zeile 12 den ich mir aber nicht erklaeren kann. :(
Kann mir hier jemand weiter helfen oder mir vielleicht einen anderen loesungsweg zeigen?
Danke fuer eure Hilfe,
Sascha