hello,
can anybody help me to answer the question why curl (Var1) works and fsockopen(var2) not ??????
Var1:
$url = "http://xmltest.server.com/servlet/Test";
$page = "/servlet/Test";
$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($file),
"Authorization: Basic " . $kennung
);
$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_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
$data = curl_exec($ch);
if (curl_errno($ch))
{
print "Error: " . curl_error($ch);
}
else
{
curl_close($ch);
}
Var2:
$fp = fsockopen("xmltest.server.com",80,$errstr,$errno,30);
echo "Step 2 : ".date("d.m.Y - H:i:s")."<br>\n";
if(!$fp)
{
die();
}
else
{
//$data = "postdata=".$file;
$data = addslashes($file);
$data = $file;
fputs($fp, "POST /servlet/Test HTTP/1.1\r\n");
fputs($fp, "Host: xmltest.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);
}
echo "Step 3 : ".date("d.m.Y - H:i:s")."<br>\n";
while(!feof($fp))
{
$fget = fgets($fp, 128);
$data .= $fget;
}
fclose($fp);
bye jo