I need to check if the url content type is pdf or not? I have a working code however i was wondering what's the best way to check from what i have. I don't need to display the pdf, just need to check if the content type is pdf or not? Note: This method will be called multiple times with different url, so i am not sure if i need to close the response or not.
here is my code.
private bool IsValid(string url)
{
bool isValid = false;
var request = (HttpWebRequest)WebRequest.Create(url);
var response = (HttpWebResponse)request.GetResponse();
if(response.StatusCode == HttpStatusCode.OK && response.ContentType == "application/pdf")
{
isValid = true;
}
response.Close();
return isValid;
}