I could not find the question that has already been given here in relation to my situation. From my understanding of what this code does, it should work, but I just don’t understand why it is not.
I am reading the SKU list from a text file. Each SKU is on its own line. All I have to do is pass the SKU only to my XML-RPC request and print the results. From the code I paste below, it seems to intersect the SKU, but only one valid result is returned.
If I pass each SKU manually through the $ request variable, I get valid results. I tested 5 SKUs, but I have 200 so that it actually feels so good if I could make it work. I even pulled out Lydia PHP tutorials to see if I understood something, but it didn't seem to me that my code was wrong.
I appreciate your help with this.
<?php
$list = file("skus2.txt");
print_r($list);
foreach ($list as $sku){
$server_url = "http://xxxx.xxx/webservices/index.php";
$request = xmlrpc_encode_request("catalog.findProductImagesBySku", array($sku));
$context = stream_context_create(array(
'http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request)));
$file = file_get_contents($server_url, false, $context);
$response = xmlrpc_decode($file);
print_r ($response);
}
?>
I tried it every way he feels. I was with him for hours and hours.
This is what I get in return. As you can see its failure in the first 4, even if from a print statement, it grabs the right SKU and successfully works in the last SKU. All SKUs are valid because I tested them one at a time.
Array
(
[0] => DJ750605
[1] => TO88116
[2] => TO1112516
[3] => TO1112506
[4] => ENAI200006
)
DJ750605
Warning: file_get_contents(http:
TO88116
Warning: file_get_contents(http:
TO1112516
Warning: file_get_contents(http:
TO1112506
Warning: file_get_contents(http:
ENAI200006Array
(
[0] => Array
(
[sku] => ENAI200006
[large_url] => http:
[medium_url] => http:
[thumb_url] => http:
[url] => http:
)
)
UPDATE: Working code :)
<pre>
<?php
$list = file('skus2.txt', FILE_IGNORE_NEW_LINES);
print_r($list);
foreach ($list as $sku){
$server_url = "http://xxx.com/xxx/webservices/index.php";
$request = xmlrpc_encode_request("catalog.findProductImagesBySku", array($sku));
$context = stream_context_create(array(
'http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request)));
$file = file_get_contents($server_url, false, $context);
$response = xmlrpc_decode($file);
print_r ($response);
}
?>
</pre>
Thanks again, Hooray!