与HttpClient的在.NET 4.5和C#HTTP HEAD请求 [英] HTTP HEAD request with HttpClient in .NET 4.5 and C#

查看:1274
本文介绍了与HttpClient的在.NET 4.5和C#HTTP HEAD请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆