我在这里按照解决方案实施了压缩:
但是,我的 Delete Web API 抛出异常:
public HttpResponseMessage Delete(int id)
{
if (_repo == null)
{
_uow = DependencyResolver.Current.GetService<TPS.Data.Can.IUnitOfWork>();
_repo = _uow.TradeSpendRepository;
}
if (!_repo.Delete(id))
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
_uow.Save();
return Request.CreateResponse(HttpStatusCode.OK);
}
由于内容为空,因此在 CompressedContent 的构造函数中引发异常:
if (content == null)
{
throw new ArgumentNullException("content");
}
我想返回状态码是不够的!防止此异常的最佳方法是什么?