douduan5753 2014-09-23 19:27
浏览 34
已采纳

XML解析错误:Twilio中文档元素之后的垃圾

I am running the following code, and it is showing me this error. Can someone tell me why is my xml giving a problem? When i run this in the browser I get:

XML Parsing Error: junk after document element

When I run this through Twiilio I get the following error

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\"?>
";
    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> 

I have tried everything, and was hoping I could spot the error

展开全部

  • 写回答

1条回答 默认 最新

  • doudilin1225 2014-09-24 00:58
    关注

    Twilio developer evangelist here.

    I think your problem is that you're pushing out more than just XML within that script. You start by setting the content type to XML and echoing the XML declaration, but after that you start to echo what looks like debugging commands, which aren't valid XML, so the parser throws an error.

    So, to start, I would comment out or remove anything that echos non XML content from your script.

    Let me know if that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部