How to check if a file contains html instead of true content, when using a .php download service?

StackOverflow https://stackoverflow.com/questions/7879247

Question

My C# WinForms app downloads files from a .php downloading web service.

The .php page returns error as HTML pages displayed to the user (I don't have an alternative API for this)

What would be the best way, provided a file on the disk, to: 1) identify if the file is an HTML file. 2) determine if it has the content of an error page (specified as comment tags, or plain text displayed to the user)

Thanks in advance.

Était-ce utile?

La solution

  1. You could use an HTML validator to determine if the file contains valid HTML.
  2. Depends on what an error page looks like. Instead of inspecting the file, could you look at the response's HTTP status code? This will be simpler and more semantic, provided that the PHP server sets the status code reasonably.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top