我有一个场景,我需要调用构造如下的 Web API Delete 方法:
// DELETE: api/products/{id}/headers
[HttpDelete("{id}/headers")]
public void DeleteProductHeaders(int id, [FromBody] string query)
{
}
诀窍是,为了获得查询,我需要通过正文发送它,而 DeleteAsync 没有像 post 那样的 json 参数。有谁知道我如何在 c# 中使用 System.Net.Http 客户端来做到这一点?
// Delete a product's headers
public void DeleteProductHeaders(int id, string query)
{
using (var client = GetClient())
{
HttpResponseMessage response;
try
{
// HTTP DELETE
response = client.DeleteAsync($"api/products/{id}/headers").Result;
}
catch (Exception ex)
{
throw new Exception("Unable to connect to the server", ex);
}
}
return retVal;
}