Giải thích về HttpResponseMessage?
Giải thích về HttpResponseMessage?
HttpResponseMessage (Web API 2, System.Net.Http) là đối tượng đại diện toàn bộ phản hồi HTTP: mã trạng thái, header, nội dung — cho phép kiểm soát chi tiết từng phần.
public HttpResponseMessage Get(int id)
{
var p = repo.Find(id);
if (p == null) return Request.CreateResponse(HttpStatusCode.NotFound, "Không có sản phẩm");
var res = Request.CreateResponse(HttpStatusCode.OK, p); // tự chọn định dạng (content negotiation)
res.Headers.CacheControl = new CacheControlHeaderValue { MaxAge = TimeSpan.FromMinutes(5) };
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.