Take the 2-minute tour ×

Consider the following class

public class StController:apicontroller {

    public void PostBodyMethod() {
        HttpRequestMessage request=this.request;
     //How to read the header and body parameters

The applet sends both the header and body parameters to the post method. How to retrieve the information which is sent along with post method inside the webapi controller using the HttpRequestMessage object?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If the body parameter is a JSON object, all what you need is to just pass Model parameter in Post method. Web API supports json by default. You might need to read this.

To reader headers in HttpRequest, you can use:

var headers = ControllerContext.Request.Headers;

Sample code:

class Model 
    public int Id { get; set; } 
    public int Hj { get; set; }  

public class StController : ApiController { 

    public void Post(Model model) { 

     //How to read the header and body parameters
     var headers = ControllerContext.Request.Headers;
share|improve this answer
The issue is I am calling the post method from an applet ,and the applet is sending the parameters in header and body in a parameterless method eg:Post() .I have to mandatarily use HttpRequestMessage object. Only this is I am not sure how to make use of it.Can you guide me how to use it? –  user1599992 Sep 19 '12 at 7:07
Why you mention The body parameter is a JSON object of a class? –  Cuong Le Sep 19 '12 at 7:08
Actually it is a custom class used by Java and they are sending the values in key,value pairs like {Id:1,hj:2,Id:2,hj:3}...Along with it they are also sending the header parameters like name="abcd"...So now what is the way of retreiving these values in my apicontroller? –  user1599992 Sep 19 '12 at 7:19
@user1599992: Please could you update your question for more correct? –  Cuong Le Sep 19 '12 at 7:36
Its updated along with the title –  user1599992 Sep 19 '12 at 7:57
add comment

Your Answer


