대답은 아니지만 ....라고 가정 할 것입니다. WebClient를 사용하여 HEAD 메서드를 보내고 머리글을 문자열 또는 이와 비슷한 것으로 반환하는 방법이 있습니까?HEAD with WebClient?
답변
당신이 맞아 WebClient가 이것을 지원하지 않습니다. 당신의 HttpWebRequest를 사용하고이 기능하려면 머리에 방법을 설정할 수 있습니다 :이 방법을 받아 들일 것입니다로부터 요청
System.Net.WebRequest request = System.Net.WebRequest.Create(uri);
request.Method = "HEAD";
request.GetResponse();
대부분의 웹 서버를. 모든 웹 서버가 그런 것은 아닙니다. 예를 들어, IIS6은 요청 방법 인 SOMETIMES를 존중할 것입니다.
이 방법이 허용되지 때 반환되는 상태 코드는 ...
catch (WebException webException)
{
if (webException.Response != null)
{
//some webservers don't allow the HEAD method...
if (((HttpWebResponse) webException.Response).StatusCode == HttpStatusCode.MethodNotAllowed)
감사합니다, 마이크
또 다른 방법은 웹 클라이언트에서 상속 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;
}
}
+1 웹 클라이언트가 훨씬 사용하기 쉽습니다. –
초보자의 경우이 재정의 된 클래스를 어떻게 호출합니까? – bendecko
'var wc = new WebClient(); 대신'var wc = new ExWebClient();' – tomfanning
- 1. WebClient 문제
- 2. WebClient 개체를 사용한 예외 처리
- 3. WebClient 업로드 파일 문제
- 4. webclient 및 expect100continue
- 5. WebClient, UploadString은 무엇을합니까?
- 6. C# WebClient OpenRead url
- 7. webClient Bot - 멀티 스레딩
- 8. WebClient 업로드 파일 오류
- 9. Lazy WebClient 다운로드
- 10. WebService 내에서 WebClient 호출하기
- 11. WebClient 쿠키 혼동
- 12. Silverlight WebClient 동시성 제한?
- 13. webclient 업로드 오류
- 14. WebClient DownloadFileAsync File Exists
- 15. .net webclient javascript 문제
- 16. WCF + WebClient + Powershell
- 17. WebClient 시간 초과 문제
- 18. https가있는 C# WebClient
- 19. C# WebClient 메모리 사용량
- 20. WebClient 구축 오버 헤드
- 21. WebClient 인코딩 문제는 vb.net
- 22. WebClient 다시 시도
- 23. WebClient 오류를 문자열로 가져 오기
- 24. PHP - 그것이 같은 <head></head> 데이터
- 25. HTML 양식 method = "HEAD"
- 26. 힘이 HEAD ~ 7로 되돌아갑니다.
- 27. 힘내 : 치명적인 오류 : HEAD '
- 28. jQuery floating head strangeness
- 29. Ping vs HTTP HEAD
- 30. svn BASE가 HEAD
WebClient가 HEAD 요청을 보낼 수 있는지 여부에 대한 질문에 대답하지 않습니다. –