[code=php]<?php
$td_sku="108896 3";
//Following the XML data
$xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
<OnlineCheck> \r
<Header>\r
<BuyerAccountId >----------</BuyerAccountId> \r
<AuthCode>----------</AuthCode>\r
<Type>Full</Type>\r
</Header>\r
<Item line=\"1\">\r
<ManufacturerIt emIdentifier/>\r
<ResellerItemId entifier/>\r
<DistributorIte mIdentifier>$td _sku</DistributorItem Identifier>\r
<Quantity>1</Quantity>\r
</Item>\r
</OnlineCheck>";
$fp = fsockopen("some website.com", 8080, $errno, $errstr, 30);
//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; boundary=---------------------------2\r
";
$out3 = "Host: somewebsite.com :8080\r
";
$out5 = "Connection : close\r
\r
";
$out6 = "-----------------------------2\r
";
$out7 = "Content-Disposition: form-data; name=\"onlinech eck\"\r
\r
";
$out8 = "\r
-----------------------------2--";
//Calculation of the Content-Length:
$tlen=strlen($o ut6)+strlen($ou t7)+strlen($xml data)+strlen($o ut8);
$out4 = "Content-Length: $tlen\r
";
//Generate full output
$out = $out1.$out2.$ou t3.$out4.$out5. $out6.$out7.$xm ldata.$out8;
fwrite($fp, $out);
$retval = "";
while(!feof($fp )){$retval = "$retval".fgets ($fp,128);}
fclose($fp);
list($headers,$ body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval) ;
$doc = new DOMDocument();
$doc ->LoadXML($body) ;
$item_ids = $doc->getElementsByT agname( "OnlineChec k" );
foreach( $item_ids as $item )
{
// $error_s = $item->getElementsByT agName( "Errorstatu s" ); $tderror = $error_s->item(0)->nodeValue;
$stock_s = $item->getElementsByT agName( "AvailabilityTo tal" ); $tdstock = $stock_s->item(0)->nodeValue;
// Reformatting the price to ISO compatible format
$price_s = $item->getElementsByT agName( "UnitPriceAmoun t" ); $tdprice = str_replace('.' ,'',$price_s->item(0)->nodeValue);
$tdprice=str_re place(',','.',$ tdprice);
}
//Rest of handling off the data under here
echo "Stock: ".$tdstock. "<BR />";
echo "Price: ".&tdprice;
?>[/code]
Besides removing the account number and website for security, all I've done to this code is attempt to echo the results of the returned data.
All that is returned, is a completely blank page.
I've tried adding
And still, the page is completely blank.
I added a few echo's scattered at various parts and got results. I echoed $td_sku; $xml and $out, all just after they were 'created', so I know that the echo code I was using worked. I think there must be something below the $retval that's wrong.
I'm sure I had it working the other day; but I had the php hosted on a different site which I can't access at the moment.
Can anyone see anything obviously wrong; or suggest something to try?
Thanks
Mandi
$td_sku="108896 3";
//Following the XML data
$xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
<OnlineCheck> \r
<Header>\r
<BuyerAccountId >----------</BuyerAccountId> \r
<AuthCode>----------</AuthCode>\r
<Type>Full</Type>\r
</Header>\r
<Item line=\"1\">\r
<ManufacturerIt emIdentifier/>\r
<ResellerItemId entifier/>\r
<DistributorIte mIdentifier>$td _sku</DistributorItem Identifier>\r
<Quantity>1</Quantity>\r
</Item>\r
</OnlineCheck>";
$fp = fsockopen("some website.com", 8080, $errno, $errstr, 30);
//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; boundary=---------------------------2\r
";
$out3 = "Host: somewebsite.com :8080\r
";
$out5 = "Connection : close\r
\r
";
$out6 = "-----------------------------2\r
";
$out7 = "Content-Disposition: form-data; name=\"onlinech eck\"\r
\r
";
$out8 = "\r
-----------------------------2--";
//Calculation of the Content-Length:
$tlen=strlen($o ut6)+strlen($ou t7)+strlen($xml data)+strlen($o ut8);
$out4 = "Content-Length: $tlen\r
";
//Generate full output
$out = $out1.$out2.$ou t3.$out4.$out5. $out6.$out7.$xm ldata.$out8;
fwrite($fp, $out);
$retval = "";
while(!feof($fp )){$retval = "$retval".fgets ($fp,128);}
fclose($fp);
list($headers,$ body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval) ;
$doc = new DOMDocument();
$doc ->LoadXML($body) ;
$item_ids = $doc->getElementsByT agname( "OnlineChec k" );
foreach( $item_ids as $item )
{
// $error_s = $item->getElementsByT agName( "Errorstatu s" ); $tderror = $error_s->item(0)->nodeValue;
$stock_s = $item->getElementsByT agName( "AvailabilityTo tal" ); $tdstock = $stock_s->item(0)->nodeValue;
// Reformatting the price to ISO compatible format
$price_s = $item->getElementsByT agName( "UnitPriceAmoun t" ); $tdprice = str_replace('.' ,'',$price_s->item(0)->nodeValue);
$tdprice=str_re place(',','.',$ tdprice);
}
//Rest of handling off the data under here
echo "Stock: ".$tdstock. "<BR />";
echo "Price: ".&tdprice;
?>[/code]
Besides removing the account number and website for security, all I've done to this code is attempt to echo the results of the returned data.
All that is returned, is a completely blank page.
I've tried adding
Code:
error_reporting(E_ALL);
ini_set('display_errors', true);
I added a few echo's scattered at various parts and got results. I echoed $td_sku; $xml and $out, all just after they were 'created', so I know that the echo code I was using worked. I think there must be something below the $retval that's wrong.
I'm sure I had it working the other day; but I had the php hosted on a different site which I can't access at the moment.
Can anyone see anything obviously wrong; or suggest something to try?
Thanks
Mandi
Comment