Identifying data format in web service

1

Good evening! I am implementing a service on a system for other systems to consume. This system consumes data in XML and JSON formats. I want to know if you have any way to identify when the user sends a string in XML format. Here's my code.

        $(function() {
        $.ajax({
            type: "post",
            contentType: "application/xml; charset=utf-8",
            url: 'http://www.e-sms.com.br/api',
            data: { 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>"},
            dataType: "json",
            success: function(data){
                console.log(data);
            },
            error: function (request){
                console.log(request);
            }
        });        
    });

This code works when the ContentType property is removed. So far, I'm believing that ContentType is the secret. My server has the following header.

header('Access-Control-Allow-Headers: *');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/json; charset=utf-8');

Header, on the server side uses the default Content-Type. I believe that by setting this attribute in my Ajax request, I would be deleting it to the server that uses it. But I can not make it work. Can anyone help me?

    
asked by anonymous 07.07.2016 / 22:24

0 answers