I am trying to use WebClient
to download a file from web using a WinForms application. However, I really only want to download HTML file. Any other type I will want to ignore.
I checked the WebResponse.ContentType
, but its value is always null
.
Anyone have any idea what could be the cause?
I apologize for not been very clear. I wrote a wrapper class that extends WebClient. In this wrapper class, I added cookie container and exposed the timeout property for the WebRequest.
I was using DownloadDataAsync() from this wrapper class and I wasn't able to retrieve content-type from WebResponse of this wrapper class. My main intention is to intercept the response and determine if its of text/html nature. If it isn't, I will abort this request.
I managed to obtain the content-type after overriding WebClient.GetWebResponse(WebRequest, IAsyncResult) method.
The following is a sample of my wrapper class: