Post parameter is always null

I have been scratching my head over this today.

My solution is to change the [FromBody] to a HttpRequestMessage, essentially moving up the HTTP stack.

In my case I am sending data across the wire which is zipped json which is then base64’d. All this from an android app.

The original signature of my web endpoint looked like this (using [FromBody]) :

My original endpoint

My fix for this issue was to revert to using a HttpRequestMessage for the signature of my endpoint.

enter image description here

You can then get access to the post data using this line of code:

enter image description here

This works and allows you access to the raw untouched post data. You don’t have to mess around with fiddler putting an = sign at the beginning of your string or changing the content-type.

As an aside, I first tried to following one of the answers above which was to change the content type to: “Content-Type: application/x-www-form-urlencoded”. For raw data this is bad advice because it strips out + characters.

So a base64 string that starts like this: “MQ0AAB+LCAAAAAA” ends up like this “MQ0AAB LCAAAAAA”! Not what you want.

Another benefit of using HttpRequestMessage is that you get access to all the http headers from within your endpoint.

Leave a Comment