与HttpClient的在.NET 4.5和C#HTTP HEAD请求 [英] HTTP HEAD request with HttpClient in .NET 4.5 and C#
问题描述
是否有可能创建.NET 4.5与新的的HttpClient
一个HTTP HEAD请求?唯一的方法我能看到的是 GetAsync
, DeleteAsync
, PutAsync
和 PostAsync
。我知道的HttpWebRequest
级是能够做到这一点,但我想用现代的HttpClient
。
Is it possible to create a HTTP HEAD request with the new HttpClient
in .NET 4.5? The only methods I can find are GetAsync
, DeleteAsync
, PutAsync
and PostAsync
. I know that the HttpWebRequest
-class is able to do that, but I want to use the modern HttpClient
.
推荐答案
使用 SendAsync
法 HttpRequestMessage
这是利用人工 HttpMethod.Head
。
GetAsync
, PostAsync
等是的convenient包装的周围 SendAsync
;不太常见的HTTP方法,如 HEAD
,选项
等,没有得到的包装。
GetAsync
, PostAsync
, etc are convenient wrappers around SendAsync
; the less common HTTP methods such as HEAD
, OPTIONS
, etc, don't get a wrapper.
这篇关于与HttpClient的在.NET 4.5和C#HTTP HEAD请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!