简体   繁体   English

使用.php下载服务时,如何检查文件是否包含html而不是真实内容?

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

My C# WinForms app downloads files from a .php downloading web service. 我的C#WinForms应用程序从.php下载Web服务下载文件。

The .php page returns error as HTML pages displayed to the user (I don't have an alternative API for this) 当向用户显示HTML页面时,.php页面返回错误(我没有替代的API)

What would be the best way, provided a file on the disk, to: 1) identify if the file is an HTML file. 提供磁盘上的文件,最好的方法是:1)识别文件是否为HTML文件。 2) determine if it has the content of an error page (specified as comment tags, or plain text displayed to the user) 2)确定它是否具有错误页面的内容(指定为注释标签或显示给用户的纯文本)

Thanks in advance. 提前致谢。

  1. You could use an HTML validator to determine if the file contains valid HTML . 您可以使用HTML验证程序确定文件是否包含有效的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 ? 您可以查看响应的HTTP状态代码 ,而不是检查文件吗? This will be simpler and more semantic, provided that the PHP server sets the status code reasonably. 只要PHP服务器合理地设置状态代码,这将更加简单和语义化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM