0

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.

Lockszmith
  • 2,173
  • 1
  • 29
  • 43
  • 1
    Check the response headers, these should contain an error code (`Status-code`?). `Content-type`, `Content-disposition` and so on, if there isn't a specific one containing an error code. – Grant Thomas Oct 24 '11 at 17:13
  • So if I'm using System.Net.WebClient's DownloadFileAsync, I should first force a request with only reading the response to determine if an error occurred or not? – Lockszmith Oct 24 '11 at 17:16

1 Answers1

1
  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.
Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Thanks for the idea, but not sure an HTML validator is what I want (too overkill for a small app), however the HTTP status code does make sense, I'll see how I can validate that prior to starting the download. Thanks! – Lockszmith Oct 24 '11 at 17:22
  • HTTP status codes are of no use, the php script always return 200 OK, hopefully will find another way, will update if found – Lockszmith Nov 02 '11 at 19:53