Search code examples
c#htmlxmlhttpwebrequestxmlreader

C# HttpWebRequest - How to disgtinguish between HTML and XML pages without downloading?


I need to be able to tell if a link (URL) points to an XML file (RSS feed), or a regular HTML file just by looking at the headers, or something similiar (without downloading it)

Any good advice for me there ? :)

Thanks! Roey


Solution

  • You could just do a HEAD request instead of a full POST/GET

    That will get you the headers for that page which should include the content type. From that you should be able to distinguish if its text/html or xml

    Theres a good example here on SO