错误 - 它们意味着什么?除了示例代码之外还有另一种方法来提取数据吗?

时间:2011-04-01 04:09:04

标签: php xml simplexml

我正在尝试从api cart中提取数据,但我对API或PHP没有经验 - 尝试使用API​​仍然是我的第一次经验。我想知道错误是什么意思。另外我想知道是否可以以简单的方式进行,以便它可以应用于html页面仅显示图像? CURL已在服务器上启用。

错误示例

Error 1Auth failed.
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/images/test.php on line 17

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: 1 in /var/www/images/test.php on line 17

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /var/www/images/test.php on line 17

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/images/test.php:17 Stack trace: #0 /var/www/images/test.php(17): SimpleXMLElement->__construct('1') #1 {main} thrown in /var/www/images/test.php on line 17

PHP示例

 <?php
    $shop='www.shop.com/content/admin/plugins/api/index.php?';
    $user = "dsp";
    $password = "ds127";
    $token = 'token';

    // Assemble the account url
    $url = 'https://'.$shop."username=".$user."&amp;password=".$password."&amp;token=".$token. "&apiType=xml&call=GetProducts";

    // Setup the cURL object
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt( $curl, CURLOPT_URL, $url );

    $response=curl_exec($curl);
    curl_close($curl);
    $image_xml = new SimpleXMLElement($response);
  foreach($image_xml->ThumbnailImageUrl as $thumbs){
echo "<img src=".$thumbs."/>";
}

    ?>

1 个答案:

答案 0 :(得分:1)

更改

curl_setopt($l_oCurl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POST, 1);