2014-09-24 125 views
0

我正在运行以下代码,并且它向我显示此错误。有人能告诉我为什么我的XML给出了一个问题?当我在浏览器中运行这个,我得到:XML解析错误:Twilio中的文档元素之后的垃圾

XML Parsing Error: junk after document element 

当我运行此通过Twiilio我收到以下错误

parserMessage Error on line 2 of document : Content is not allowed in prolog. 

<?php 

    header("content-type: text/xml"); 
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
    require "twilio-php-latest/Services/Twilio.php"; 

     /* Set our AccountSid and AuthToken */ 
    $AccountSid = "xxxxx"; 
    $AuthToken = "xxxx"; 

    include 'db.php'; 
    $caller=$_REQUEST['From']; 
    /* Instantiate a new Twilio Rest Client */ 
    $client = new Services_Twilio($AccountSid, $AuthToken); 

    $from= "+17864310795"; 
    $student_number=substr($caller,1); 
     $db = new PDO("mysql:host=localhost;dbname=xxxx","xxxx","xxxx"); 
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $studentData=getSingleStudentData($db,$student_number); 
    foreach($studentData as $key=>$val) 
    { 
     $student_id=$val['student_id']; 
     $phone=$val['phone_number']; 
     $status=$val['status']; 
     echo $student_id; 
     // find out last call successfully completed by the student 
     if($status==1) 
     { 
      $progress = getLastActivity($db,$student_id); 
X 
X 
X 
echo "done with initialize<br/>"; 
      $server= "http://sample.com"; 


     try { 
      $to = '+' . $phone;    
      echo $phone; 
      $questions_id_url='questions_id_0='.$questions_id[0].'&questions_id_1='.$questions_id[1].'&questions_id_2='.$questions_id[2]; 
      $questions_file_url='questions_file_0='.$questions_file[0].'&questions_file_1='.$questions_file[1].'&questions_file_2='.$questions_file[2]; 
      $url = $server.'/startCall.php?call_id='.$call_id.'&phone='.$phone.'&'.$questions_id_url.'&'.$questions_file_url.'&student_id='.$student_id.'&story=' 
      .$story.'&story_id='.$story_id.'&call_number='.$call_number.'&question_number=0&count_english=0&count_hindi=0&insert_receivecall=0'; 
      echo "here"."-----".$url; 
      $client->account->calls->create(
      "+17864310795", 
      $to, 
      $url, 
      array(
      'Method' => "GET", 
      'FallbackMethod' => "GET", 
      'StatusCallbackMethod' => "GET", 
      'Record' => "false", 
      )); 
     } catch (Exception $e) { 
      // log error 
     } 
     } 
    } 
?> 
<Response> 
    <Reject reason="busy"/> 
</Response> 

我已经尝试了一切,并希望我能找到这个错误

回答

3

Twilio开发人员在这里传播。

我认为你的问题在于你在该脚本中推出的不仅仅是XML。您首先将内容类型设置为XML并声明XML声明,但在此之后,您将开始到echo看起来像调试命令(它不是有效的XML),因此解析器会引发错误。

因此,首先,我会注释掉或删除脚本中非XML内容的任何内容。

让我知道是否有帮助。

相关问题