XData Service Operation, how to accept a POST Request with Content-Type: text/plain

I have a XData Service and a 3rdParty client is calling it. It makes POST Requests where the Content-Type is text/plain instead of the usual/proper application/json
Unfortunately I can not change the 3rdParty client.

currently XData raises an error and responds with this:

"error": {
"code": "UnsupportedMediaType",
"message": "Unsupported media type: text/plain"

my (simplified) Service looks like that:

IMyService = Interface(IInvokable)

Function Upload(body: TJsonObject): TJsonObject;


a sample curl call would look like that:

curl -X 'POST'
-H 'Content-Type: text/plain'
-d '{"type":"sampleJson","level":"WARNING","data":"some data"}'

is there a way I can make XData accept text/plain?
Extra points if I could read the POST payload as a string or stream, as the json might be malformed sometimes.

thanks in advance

A JSON is a JSON, so text/plain is simply wrong. XData would deserialize JSON.
Now, if you want to receive an arbitrary content, just declare your parameter as TStream. You will receive the text raw content in it and then you can do whatever you want with it:

Function Upload(body: TStream): TJsonObject;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.