代码改变世界

asp.net mvc 4 Rp Web API的变化

2012-06-15 11:37  杰出的世界  阅读(322)  评论(0编辑  收藏  举报

这几天在做Web API 的练习,做到Post数据的时候发现一个问题。HttpResponseMessage不再有泛型的重载。

官方的示例如下:

 

From the release notes:

Removed HttpRequestMessage<T> and HttpResponseMessage<T>:
Previously there were two ways to specify a request or response with an ObjectContent instance: you could provide an ObjectContentinstance directly, or you could use HttpRequestMessage<T> or HttpResponseMessage<T>. Having two ways of doing the same thing complicated request and response handling, so HttpRequestMessage<T> and HttpResponseMessage<T> have been removed. To create content negotiated responses that contain an ObjectContent use the CreateResponse<T> extension methods on the request message. To send a request that contains an ObjectContent use the PostAsync<T> extension methods on HttpClient. Or, use thePostAsJsonAsync<T> and PostAsXmlAsync<T> extension methods to specify a request that will be specifically formatted with as JSON or XML respectively.

只是简单的添加,没有做异常判断。相比Beta版本,简化了一些。

如果需要添加Location信息,直接加上即可。

 

参考网站:http://forums.asp.net/t/1813881.aspx/1?What+to+use+instead+of+HttpResponseMessage+T+