1

I have checked similar questions to this here:

web-api POST body object always null

This does not exactly match what is happening in my scenario. I am making a request to my api with the following request header content-type:

Key Value
Content-Type    application/x-www-form-urlencoded

My request body then is a Response I get from another service which I cannot change

Response=SomeLongStringOfBAse64EncodedData

My Api Post Method which I can see gets hit by setting a breakpoint on it is as:

public HttpResponseMessage Authenticate([FromBody]string Response) 

However Response string is always getting null value even though I see it in the request body which I cannot understand.

Community
  • 1
  • 1
TheRiddler
  • 169
  • 3
  • 16
  • How are you calling `Authenticate`? – Christian Phillips Nov 06 '14 at 21:29
  • a page gets loaded in my website - it has a hidden form with a POST action on it. The action on it is my Authenticate URL route and the the form also contains the Response Base 64 string. I think the Request is being made ok as I hit the breakpoint - just cant figure out why the Request Body isnt binding to my parameter – TheRiddler Nov 06 '14 at 21:36
  • @TheRiddler Please post how the call the `Authenticate` is made and the route for the action too. – Francis Ducharme Nov 06 '14 at 21:56

1 Answers1

0

For an action method like this

public HttpResponseMessage Authenticate([FromBody]string Response),

you need to have the request body like this, for binding to work.

=SomeLongStringOfBAse64EncodedData

If you want to bind Response=SomeLongStringOfBAse64EncodedData, you will need to change the action method like this.

public HttpResponseMessage Authenticate(SomeClass response)

and add a class

public class SomeClass
{
    public string Response { get; set; }
}
  • The FromBody can be tricky, a few issues I have found in iOS, if your using RestKit - I had to post it as json with the single property being empty quotes. ''='value'. In Android, if you use Retrofit - then as long as you post it with @Body, the webapi will pick it up. – Kalel Wade Feb 26 '15 at 17:42
  • You don't need to prefix it with '=' sign if you use JSON.stringify(item); – MIWMIB Apr 02 '15 at 11:02