您好,這是某一條mvc4的WebAPI代碼任何人都可以在這裏解釋一下我的每一行的code..I google搜索,但沒有發現任何東西有趣關於mvc4網頁API
public HttpResponseMessage PostProduct(Product item)
{
item = repository.Add(item);
var response = Request.CreateResponse(HttpStatusCode.Created, item);
string uri = Url.RouteUrl("DefaultApi", new { id = item.Id });
response.Headers.Location = new Uri(uri);
return response;
}
我只知道,我送作爲回報產品item..and這個網頁API返回我新添加的產品的反應,但我不明白這2條線特別
string uri = Url.RouteUrl("DefaultApi", new { id = item.Id });
response.Headers.Location = new Uri(uri);
請務必檢查所有的答案,作爲接受的標記回答的
GET
操作方法。 –