HEAD with WebClient?

前端 未结 3 1085
挽巷
挽巷 2020-12-03 20:35

I am going to assume the answer is no but.... Is there a way to use WebClient to send the HEAD method and return the headers as a string or something similar?

3条回答
  •  执笔经年
    2020-12-03 21:08

    Another way is to inherit from WebClient and override GetWebRequest(Uri address).

        public class ExWebClient : WebClient
        {
            public string Method
            {
                get;
                set;
            }
    
            protected override WebRequest GetWebRequest(Uri address)
            {
                WebRequest webRequest = base.GetWebRequest(address);
    
                if (!string.IsNullOrEmpty(Method))
                    webRequest.Method = Method;
    
                return webRequest;
            }
        }
    

提交回复
热议问题