为什么我应该使用 get 而不是 post?
Why should i use get instead of post?
我有一个用 mvc c# 开发的 Web 服务,该服务的目的是检索数据并将数据插入 sql。所有方法都使用 http 属性,所以我的问题是,如果所有方法都使用 [HttpPost] 并且工作正常,我应该什么时候使用 [HttpGet].
[HttpPost]
[Route("GetVehiculos")]
public HttpResponseMessage WSGetVehiculos()
{
VehiculosDAO vehiculosDAO = new VehiculosDAO();
List<Vehiculo> lstVehiculo = new List<Vehiculo>();
string codError = "0";
string mensaje = "";
try
{
lstVehiculo = vehiculosDAO.GetVehiculos();
mensaje = "OK";
}
catch (Exception ex)
{
codError ="1";
Log.WriteToFileLogGeneral(ex.Message);
}
return Request.CreateResponse(HttpStatusCode.OK, new { Msg = mensaje, CodError =
codError,Data= lstVehiculo } );
}
提前致谢
GET 用于查看某些内容,而不更改它,而 POST 用于更改某些内容。例如,搜索页面应使用 GET 获取数据,而更改密码的表单应使用 POST。本质上GET用于获取远程数据,POST用于insert/update远程数据。
我有一个用 mvc c# 开发的 Web 服务,该服务的目的是检索数据并将数据插入 sql。所有方法都使用 http 属性,所以我的问题是,如果所有方法都使用 [HttpPost] 并且工作正常,我应该什么时候使用 [HttpGet].
[HttpPost]
[Route("GetVehiculos")]
public HttpResponseMessage WSGetVehiculos()
{
VehiculosDAO vehiculosDAO = new VehiculosDAO();
List<Vehiculo> lstVehiculo = new List<Vehiculo>();
string codError = "0";
string mensaje = "";
try
{
lstVehiculo = vehiculosDAO.GetVehiculos();
mensaje = "OK";
}
catch (Exception ex)
{
codError ="1";
Log.WriteToFileLogGeneral(ex.Message);
}
return Request.CreateResponse(HttpStatusCode.OK, new { Msg = mensaje, CodError =
codError,Data= lstVehiculo } );
}
提前致谢
GET 用于查看某些内容,而不更改它,而 POST 用于更改某些内容。例如,搜索页面应使用 GET 获取数据,而更改密码的表单应使用 POST。本质上GET用于获取远程数据,POST用于insert/update远程数据。