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, '<' 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 <?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->finalize(Object(Slim\Http\Response))#1 C:\xampp\htdocs\SITE\vendor\slim\slim\Slim\App.php(298): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))#2 C:\xampp\htdocs\SITE\lib\api\api.php(71): Slim\App->run()#3 C:\xampp\htdocs\SITE\lib\api\api.php(40): lib\api\api->create_routes()#4 C:\xampp\htdocs\SITE\lib\api\api.php(33): lib\api\api->initialize()#5 C:\xampp\htdocs\SITE\lib\api\api.php(76): lib\api\api->__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 saw some solutions that indicate using an extension called Middleware. He does the parse. With the command Composer required slim/slim " 3.0" Middle is already installed. The app cannot find the Contenttype.php class. I believe that a feature like Composer already leaves the application with satisfied dependencies. Following that line of reasoning I don’t care about that.
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 idea how I can fix this ?