Jump to content

curl works fine, fsockopen not !


jogisarge

Recommended Posts

hello,

 

can anybody give me a answer why var1(curl) works an var2(fsockopen) fails ????

in var2 the server answers with the error "Parameter document is missing" ????

is this a http parameter, or what ??

 

 

 

Variante 1:

$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);
}

 

Variante 2:

$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

Link to comment
https://forums.phpfreaks.com/topic/108809-curl-works-fine-fsockopen-not/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.