【发布时间】:2018-05-28 12:25:03
【问题描述】:
我正在尝试向服务器发送请求以根据 id 删除对象。我使用 Web Api 作为后端。
角度
removable: string = 'http://localhost:49579/api/resource/remove/28';
this._http.options(removable,{headers}).subscribe((value)=>console.log("success"),(error)=>console.log(error));
WebApi
[HttpOptions]
[Route("api/resource/remove/{id}")]
public IHttpActionResult Delete([FromUri] int id)
{
if (MovieRepository.Remove(id))
{
return Ok("Movie was removed");
}
else
{
return BadRequest("Movie was not removed");
}
}
}
我收到两个请求,一个是 OK,另一个是 Bad Request。我也用 Http DELETE 尝试过,但它产生了相同的效果。我做错了什么?
【问题讨论】: