Put content in HttpResponseMessage object?

后端 未结 8 1534
感情败类
感情败类 2020-11-28 03:31

Several months ago, Microsoft decided to change up the HttpResponseMessage class. Before, you could simply pass a data type into the constructor, and then return the message

8条回答
  •  无人及你
    2020-11-28 03:44

    Apparently the new way to do it is detailed here:

    http://aspnetwebstack.codeplex.com/discussions/350492

    To quote Henrik,

    HttpResponseMessage response = new HttpResponseMessage();
    
    response.Content = new ObjectContent(T, myFormatter, "application/some-format");
    

    So basically, one has to create a ObjectContent type, which apparently can be returned as an HttpContent object.

提交回复
热议问题