HEAD with WebClient?

前端 未结 3 1094
挽巷
挽巷 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:07

    Most web servers that I request from will accept this method. Not every web server does though. IIS6, for example, will honor the request method SOMETIMES.

    This is the status code that is returned when a method isn't allowed...

    catch (WebException webException)
                {
                        if (webException.Response != null)
                        {
                            //some webservers don't allow the HEAD method...
                            if (((HttpWebResponse) webException.Response).StatusCode == HttpStatusCode.MethodNotAllowed)
    

    Thanks, Mike

提交回复
热议问题