Slim Framework simplexml_load_string parser error

0

My application sends a string in XML format to the server.

        $(function() {

        var xml = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>";
        $.ajax({
            type: "post",
             data: { xml : xml},
             contentType: "application/xml; charset=UTF-8; charset=utf-8",
            dataType: "json",
            url: 'http://www.e-sms.com.br/api',
            success: function(data){
                console.log(data);
            },
            error: function (request){
                console.log(request);
            }
        });    
    });
    </script>

I get the following error.

"<br /><b>Warning</b>:  simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '&lt;' not found in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Warning</b>:  simplexml_load_string(): xml=%3C%3Fxml%20version%3D'1.0'%20encoding%3D'UTF-8'%3F%3E%20%3Cnote%3E%20%3Cto% in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Warning</b>:  simplexml_load_string(): ^ in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\Http\Request.php</b> on line <b>202</b><br /><br /><b>Fatal error</b>:  Uncaught exception 'RuntimeException' with message 'Unexpected data in output buffer. Maybe you have characters before an opening &lt;?php tag?' in C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php:552Stack trace:#0 C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php(344): Slim\App-&gt;finalize(Object(Slim\Http\Response))#1 C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php(298): Slim\App-&gt;process(Object(Slim\Http\Request), Object(Slim\Http\Response))#2 C:\xampp\htdocs\SITE\lib\api\api.php(71): Slim\App-&gt;run()#3 C:\xampp\htdocs\SITE\lib\api\api.php(40): lib\api\api-&gt;create_routes()#4 C:\xampp\htdocs\SITE\lib\api\api.php(33): lib\api\api-&gt;initialize()#5 C:\xampp\htdocs\SITE\lib\api\api.php(76): lib\api\api-&gt;__construct()#6 {main}  thrown in <b>C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php</b> on line <b>552</b><br />"

The Slim Framework has little documentation. I have seen some solutions that indicate using an extension called Middleware. He does the parse. With the required composer command slim / slim "^ 3.0" the middle is already installed. The app can not find the ContentType.php class. I believe that a feature like composer already leaves the application with the dependencies satisfied. Following this line of reasoning I do not worry about it.

My application can transfer data using

            contentType: "application/json; charset=UTF-8; charset=utf-8",
            contentType: "application/x-www-form-urlencoded; charset=UTF-8; charset=utf-8"

The problem is with XML. Any ideas how I can resolve this?

    
asked by anonymous 12.07.2016 / 17:41

1 answer

0

Man, apparently you're passing xml and the slim parser does not understand. I imagine the problem is here:

data: { xml : xml}

It is unlikely that the above code will send an xml as a string. Just try:

data: {xml}

One way to check what's coming up on the server is to return what was sent and see the response in the browser's tools.

    
23.07.2016 / 06:18