Page 1 of 1

CURL and fsockopen

Posted: Wed Sep 17, 2008 4:59 am
by rsmarsha
A supplier we have a live XML stock check setup with has changed their requirements for requesting from using fopen to fsockopen. We use CURL for all but one of the other feed requests which runs fopen.

My question is, to use CURL does it need to be installed on the server your sending the request to, or just on your server?

Also is there anything that can stop fsockopen from working in a server setup? As the example files they have given me don't seem to work when tested. I'm trying to work out where the issue is as the xml i'm sending is the xml they provide with our details inserted.

When using the example php script I get the following error:
Your browser sent a request that this server could not understand.
Request header field is missing ':' separator.

<OnlineCheck>
The script itself is :

Code: Select all

 
<?php
// First we need to feed the techdata SKU, for now we use 1088963 as an example 
$td_sku='123456';
//Following the XML data
$xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
<OnlineCheck>\r
<Header>\r
<BuyerAccountId>123123</BuyerAccountId>\r
<AuthCode>code here</AuthCode>\r
<Type>Full</Type>\r
</Header>\r
<Item line=\"1\">\r
<ManufacturerItemIdentifier/>\r
<ResellerItemIdentifier/>\r
<DistributorItemIdentifier>$td_sku</DistributorItemIdentifier>\r
<Quantity>1</Quantity>\r
</Item>\r
</OnlineCheck>";
 
echo '<pre>'.$xmldata.'</pre>';
 
//Test
$fp = fsockopen("url", 8080, $errno, $errstr, 15);
 
//Generate the postdata on a valid way, $out4 needs to be calculated, so will be later.
$out1 = "POST /Onlchk HTTP/1.0\r";
$out2 = "Content-Type: multipart/form-data;\r boundary=---------------------------2\r";
$out3 = "Host: intcom.xml.quality.techdata.de:8080\r";
$out5 = "Connection: close\r\r";
$out6 = "-----------------------------2\r";
$out7 = "Content-Disposition: form-data; name=\"onlinecheck\"\r\r";
$out8 = "\r-----------------------------2--";
//Calculation of the Content-Length:
 
$tlen=strlen($out6)+strlen($out7)+strlen($xmldata)+strlen($out8);
$out4 = "Content-Length: $tlen\r";
 
//Generate full output
 
$out = $out1.$out2.$out3.$out4.$out5.$out6.$out7.$xmldata.$out8;
fwrite($fp, $out);
$retval = "";
while(!feof($fp)){$retval = "$retval".fgets($fp,128);}
fclose($fp);
 
$xmlResponse = $retval;
echo '<pre>'.$retval.'</pre>';
list($headers,$body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval);
 
$doc = new DOMDocument;
$doc = LoadXML($body);
echo $body;
?>
 
I have tried a simple html form submit which works fine so it must be something in the header section of the file. The reason i'm not parsing the xml yet and just outputting $body is just to check that something is returned.


Thanks