jogisarge: Curl/fsockopen bei http post

Beitrag lesen

Hallo zusammen,

ich versuche einen HTTP_POST an einen Webservice zu schicken.
per Fsockopen bekomme ich die Meldung:
Der Service ist nicht erreichbar.
[PHP]
$file = "";
$fp1 = fopen("./anfrage.xml","r");
$kennung = base64_encode("user:pass");
while(!feof($fp1))
{
    $file1 = fgets($fp1, 100);
    $file = $file.$file1;
}

$data = "";
$fp = fsockopen("ssl://server.com",443,$errstr,$errno);
if(!$fp)
{
    die();
}
else
{
    $file = addslashes($file);
    $data = $file;
    fputs($fp, "POST /webservice/XMLServlet HTTP/1.0\r\n");
    fputs($fp, "Host: server.com\r\n");
    fputs($fp, "Authorization: Basic ".$kennung." \r\n");
    fputs($fp, "Content-length: ". strlen($data) ."\r\n");
    fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $data);
}
while(!feof($fp))
{
    $fget = fgets($fp, 128);
    $data .= $fget;
}
fclose($fp);
$xml_arr = explode("\r\n\r\n",$data);
echo $xml_arr[1];
[/PHP]

Per CURL funktioniert es
[PHP]
$credentials = "user:pass";
$request_file = "./anfrage.xml";

$fh = fopen("./anfrage.xml","r");
while(!feof($fh))
{
    $file1 = fgets($fh, 100);
    $file = $file.$file1;
}
fclose($fh);
$xml_data = $file;

$url = "https://www.server.com/webservice/XMLServlet";
$page = "/webservice/XMLServlet";
$headers = array(
"POST ".$page." HTTP/1.0",
"Content-type: text/xml;charset="utf-8"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: "run"",
"Content-length: ".strlen($xml_data),
"Authorization: Basic " . base64_encode($credentials)
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);

$data = curl_exec($ch);

if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
else
{
var_dump($data);
curl_close($ch);
[/PHP]

Kann mir jemand sagen, warum das mit fsockopen nicht geht ??!!
Ich habe einen Server, bei dem Curl nicht geht, und dort müsste ich die Fsockopen Variante nehmen.

p.s. bei fsockopen habe ich auch schon folgendes probiert :
[PHP]
$fp = fsockopen("https://www.server.com",443,$errstr,$errno);
[/PHP]
ergibt:
[PHP]
Warning: fsockopen() [function.fsockopen]: unable to connect to
<a href="https://www.server.com:443"
target="_blank">https://www.server.com:443</a> (Unable to find the socket
transport "https" - did you forget to enable it when you configured PHP?)
in /homepages/444/d123423018/htdocs/test/xml/test.php5 on line 16
[/PHP]
und
[PHP]
$fp = fsockopen("http://www.server.com",443,$errstr,$errno);
[/PHP]
ergibt:
[PHP]
Warning: fsockopen() [function.fsockopen]: unable to connect to
<a href="http://www.server.com:443" target="_blank">
http://www.server.com:443</a> (Unable to find the socket
transport "http" -
 did you forget to enable it when you configured PHP?)
in /homepages/444/d123423018/htdocs/test/xml/test.php5 on line 17
[/PHP]

Laut phpinfo ist ssl implementiert
phpinfo sagt:
[PHP]
'../configure' '--program-suffix=5' '--with-pear=/usr/lib/php5' '
--with-config-file-path=/usr/lib/php5' '--with-libxml-dir' '--with-mysqli' '
--with-kerberos' '--with-imap-ssl' '--enable-soap' '--with-xsl' '
--enable-mbstring=all' '--with-curl' '--with-mcrypt' '--with-gd' '
--with-pdo-mysql' '--with-freetype-dir' '--with-libxml-dir' '
--with-mysql' '--with-zlib' '--enable-debug=no' '--enable-safe-mode=no' '
--enable-discard-path=no' '--with-png-dir' '--enable-track-vars' '
--with-db' '--with-gdbm' '--enable-force-cgi-redirect' '--with-ttf' '
--enable-ftp' '--enable-dbase' '--enable-memory-limit' '--enable-calendar' '
--enable-wddx' '--with-jpeg-dir=/usr/src/kundenserver/jpeg-6b' '
--enable-bcmath' '--enable-gd-imgstrttf' '--enable-shmop' '
--enable-mhash' '--with-mhash' '--with-openssl' '--enable-xslt' '
--with-xslt-sablot' '--with-dom' '--with-dom-xslt' '--with-dom-exslt' '
--with-imap' '--with-iconv' '--with-bz2' '--with-gettext' '--enable-exif' '
--with-idn' '--with-sqlite' '--enable-sqlite-utf8' '--with-zip'
[/PHP]

Gruß jogi