QC中的域名计数

时间:2018-10-16 08:01:14

标签: php rest api

如何解决该错误,该错误在使用API​​获取Quality Center域计数时出现。以下是获取QC域的代码。这段代码可以在一台机器上正常工作,但是在服务器上却显示以下错误。

<?php
 $qc = curl_init();
 //create a cookie file
 $ckfile = "";
 //set URL and other appropriate options
 curl_setopt($qc, CURLOPT_URL, "http://myserver/qcbin/rest/is-authenticated");
 curl_setopt($qc, CURLOPT_HEADER, 0);
 curl_setopt($qc, CURLOPT_HTTPGET, 1);
 curl_setopt($qc, CURLOPT_RETURNTRANSFER, 1);
 //grab the URL and pass it to the browser
 $result = curl_exec($qc);
 $response = curl_getinfo($qc);

 if($response['http_code'] == "401")
  {
        $url = "http://myserver/qcbin/authentication-point/authenticate";
        $credentials = "USER:PSWD";
        $headers = array("GET /HTTP/1.1","Authorization: Basic ". base64_encode($credentials));
        curl_setopt($qc, CURLOPT_URL, $url);
        curl_setopt($qc, CURLOPT_HTTPGET,1); 
        curl_setopt($qc, CURLOPT_HTTPHEADER, $headers);
        //Set the cookie
        curl_setopt($qc, CURLOPT_COOKIEJAR, $ckfile);
        curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($qc);
        $response = curl_getinfo($qc);

        if($response['http_code'] == '200')
        {
         $domain_url = "http://myserver/qcbin/rest/domains";
         curl_setopt($qc, CURLOPT_URL, $domain_url);
         curl_setopt($qc, CURLOPT_HEADER, false);
         curl_setopt($qc, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($qc, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
         $domain_data = curl_exec($qc);

         $domains = new SimpleXMLElement($domain_data);
         $result = $domains->xpath('//Domain');
         $domain_xml = simplexml_load_string($domain_data);
         $domain_count = count($domain_xml->xpath('//Domain'));
         echo $domain_count;  
        }
    curl_close($qc);
?>

下面是错误

  

警告:SimpleXMLElement :: __ construct():实体:第10行:解析器   错误:开始和结束标记不匹配:8号线和正文   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():^ in   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():实体:第11行:解析器   错误:开始和结束标记不匹配:正文第6行和html中   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():^ in   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():实体:第12行:解析器   错误:标签html第1行中的数据过早结束   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

警告:SimpleXMLElement :: __ construct():^ in   第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php

     

致命错误:未捕获的异常:无法将字符串解析为XML   C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php:39堆栈跟踪:#0   C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php(39):   SimpleXMLElement-> __ construct('\ n \ n <...')#1 {main}抛出   在第39行的C:\ xampp \ htdocs \ metrisi \ batch \ getDefTest.php中

0 个答案:

没有答案