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

Post Raw Data In Request Body

3 Answers 539 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 05 Jun 2012, 11:27 PM
I'm trying to access a REST service that expects raw XML to be POSTed in the body of the request. I read in the forums here that the transport property of the Data Source works via the jQuery.ajax() function, so I should be able to do something like this:
var ds = new kendo.data.DataSource({
transport: {
read: {
url: "...",
dataType: "xml",
cache: false,
contentType: "application/xml",
type: "POST",
data: "<Test></Test>"
}
}
});

In Fiddler, I can see that the Content-Type of the request is indeed getting set to "application/xml". However, the body is totally empty. If I change the data parameter to use a key-value structure, then it does pass the key-value in the body of the request. I can't figure out why sending raw content in the body isn't working - does Kendo pre-process the data property in some way to disallow this kind of use?

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 08 Jun 2012, 11:59 AM
Hello David,

The dataSource is extending that data parameter via jQuery.extend() in order to append the information about paging, sorting, etc. When you extend a string, the original information is lost, that is why you should define the data parameter as an object. This behaviour could be observed without using Kendo: 
var foo = "bar";
$.extend(foo, {bar: 1}); //returns {"bar":1}
 
var bar = { foo: "bar" };
$.extend(bar, { bar: 1 }); //returns {"foo":"bar","bar":1}

I hope this information helps.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Robert
Top achievements
Rank 1
answered on 26 Jun 2012, 05:40 AM
Hi Alexander,

So in David's case how would he address the issue? I am facing a similar situation and would like to see how to do a direct post in body of a datasource read.

I have seen another post here explaining to define the data parameter as

data: { testxml: escape(
'<test></test>')} 

This means the server side will have to accept the testxml field and extract the data out of that?
Is there another way to do this?

Thanks 



0
Tony
Top achievements
Rank 2
answered on 26 Jun 2012, 02:51 PM
I've got the same question for you. I need the data source to provide the same request body format as the jquery mehod below. In the method below, data is simply set to a string and the request body is that string. 

                $.ajax({
                    contentType: "application/json; charset=utf-8",
                    type: 'POST',
                    url: "/myurl/GetData",
                    data: "21",
                    success: function (jqXHR) { processSuccess(jqXHR);},
                    dataType: "json"
                });

I have not been able to figure out how to kendo ui datasource to output a string I provide. My understanding is that the kendo ui datasource data extends the data object, the output is then put in a querystring format  "myvar=21" etc.. 

Thanks.
Tags
Data Source
Asked by
Dave
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Robert
Top achievements
Rank 1
Tony
Top achievements
Rank 2
Share this question
or