This is a migrated thread and some comments may be shown as answers.

Plain XML Payload in Datasource

6 Answers 112 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Asat
Top achievements
Rank 1
Asat asked on 07 May 2014, 10:52 AM
Hi, 

I have a web API which needs I have a web API which expect plain XML in the request body. My following program pass the XML as form data instead of raw request payload. Where am I doing wrong?

<!DOCTYPE html>
<html>
<head>
<title>Data Call</title>
<link href="kendo/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="kendo/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
<script src="kendo/js/jquery.min.js" type="text/javascript"></script>
<script src="kendo/js/kendo.web.min.js" type="text/javascript"></script>
<script type="text/javascript">
            $(document).ready(function() {
                      var dataSource = new kendo.data.DataSource({
                                                              type: "xml",
                                                              transport: {
                                                                                     read: {
                                                                                             type: 'POST',
                                                                                            dataType: "xml",
                                                                                            data: "xmlstring",
                                                                                            url: "https://9.9.9.9:8443/kendotest/api/GetAccounts",
                                                                                           data: { escape('<?xml version="1.0" encoding="UTF-8" standalone="no"?><accountrequest><accountno>23</accountno></accountrequest>')}, 
                                                                                           beforeSend: function(xhr)
                                                                                                        {
                                                                                                              xhr.setRequestHeader('X-Token','6452734413286534260')
                                                                                                         }
                                                                                        }
                                                                               }
                                                                       });
                                                                      dataSource.read();
                                                        });
                       </script>
</head>
<body>
                <div id="info"></div>
</body>  
</html>



Thanks,
Asat









6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 09 May 2014, 08:17 AM
Hello Asat,

In order to send the data as XML you will need to set the contentType option appropriately:

var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      /* omitted for brevity */
      contentType: "text/xml"
    }
  }
});


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Asat
Top achievements
Rank 1
answered on 12 May 2014, 08:20 AM
Hi Rosen, 

Thanks for your reply but I am still in dark. 

I used pure jQuery as below and it works. 

$.ajax ({
             type: "POST",
             url: "https://192.168.5.55:8443/abc/rest/crmapp/api/CrmGetAccounts",
            dataType: "xml",
          data: '<?xml version="1.0" encoding="UTF-8" standalone="no"?><GetAccountsRequest xmlns="http://www.abc.net/act/1.0"><RequestFields><Accounts><Account><AccountNumber/><AccountName/><AccountNameIndex/><RepCode/><AccountEmail/><AccountWebsite/></Account></Accounts></RequestFields><Filters><AccountNumber><Range><From>3708</From><To>3708</To></Range></AccountNumber></GetAccountsRequest>',  
               headers: { 'X-ABC-Token': '5440276274957472002' }
});

But when I try to emulate the same with Kendo.. it doesn't work.









0
Asat
Top achievements
Rank 1
answered on 12 May 2014, 08:22 AM
My current code is as below, 

var dataSource = new kendo.data.DataSource({
type: "xml",
transport: {
read: {
type: 'POST',
contentType: "text/xml",
url: "https://192.168.5.55:8443/abc/rest/crmapp/api/CrmGetAccounts",
processData: false,
dataType: "xml",
data: '<?xml version="1.0" encoding="UTF-8" standalone="no"?><GetAccountsRequest xmlns="http://www.abc.net/act/1.0"><RequestFields><Accounts><Account><AccountNumber/><AccountName/><AccountNameIndex/><RepCode/><AccountEmail/><AccountWebsite/></Account></Accounts></RequestFields><Filters><AccountNumber><Range><From>3708</From><To>3708</To></Range></AccountNumber></GetAccountsRequest>', 
headers: { 'X-Pronto-Token': '2395432833752785275' }
}
}
});
dataSource.read();
});
0
Rosen
Telerik team
answered on 12 May 2014, 08:37 AM
Hello Asat,

As you are sending data as a single string value, you will need to use the parameterMap function instead assigning it directly to the data option. Similar to the following:

var dataSource = new kendo.data.DataSource({
       type: "xml",
       transport: {
         read: {
           type: 'POST',
           contentType: "text/xml",
           url: "https://192.168.5.55:8443/abc/rest/crmapp/api/CrmGetAccounts",
           processData: false,
           dataType: "xml",         
 
           headers: { 'X-Pronto-Token': '2395432833752785275' }
         },
         parameterMap: function() {
           return '<?xml version="1.0" encoding="UTF-8" standalone="no"?><GetAccountsRequest xmlns="http://www.abc.net/act/1.0"><RequestFields><Accounts><Account><AccountNumber/><AccountName/><AccountNameIndex/><RepCode/><AccountEmail/><AccountWebsite/></Account></Accounts></RequestFields><Filters><AccountNumber><Range><From>3708</From><To>3708</To></Range></AccountNumber></GetAccountsRequest>';
         }
       }  
     });  
     dataSource.read();


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Asat
Top achievements
Rank 1
answered on 12 May 2014, 09:38 AM
Thanks Rosen. It worked.

I couldn't figured it our from the documentation. Is it not a popular practice to send plain XMLs in http requests?

regards,
Asat
0
Rosen
Telerik team
answered on 12 May 2014, 11:58 AM
Hello Asat, 

It depends on the particular scenario. Generally speaking the most common use case will be to send multiple parameters instead of single string value.
 
Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Asat
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Asat
Top achievements
Rank 1
Share this question
or