收到的 HTTP 标头对于 XSL 文件类型不正确/意外

发布于 2024-07-29 20:39:09 字数 371 浏览 2 评论 0原文

我正在使用 PHP+curl 检索 XSL 文件,但首先我想做一些最低限度的验证,以确保该文件确实是 XSL 文件。

我确保文件存在,状态代码为 200 OK,并且文件扩展名正确,但随后我想检查 Content-Type 标头。 我使用 curl_getinfo() 函数来执行此操作。 一切都很好。

但 XSL 文件始终返回“application/xml”或“text/xml”作为 Content-Type,这适用于 XML 文件。 我相信 XSL 标头应该是“application/xslt+xml”。 那么这里发生了什么以及如何确保它是一个 XSL 文档?

I'm using PHP+curl to retrieve an XSL file, but first I want to do some minimum validation that the file is really a XSL file.

I make sure the file exists, has status code 200 OK, and that it has the correct file extension, but then I want to check the header for the Content-Type. I do this using curl_getinfo() function. All fine.

But XSL files always return "application/xml" or "text/xml" as the Content-Type, which is for XML files. I believe an XSL header should be "application/xslt+xml". So what's going on here and how can I make sure it's an XSL document?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小女人ら 2024-08-05 20:39:09

您可以检查文件中的 XSLT 命名空间。
如果 PHP 版本 >= 5.1.2,请使用 SimpleXMLElement::getNamespaces()

You can check the XSLT namespace in the file.
If PHP version >= 5.1.2, use SimpleXMLElement::getNamespaces()

披肩女神 2024-08-05 20:39:09

您是否使用它来访问第三方网站或您自己配置的网站? 如果这是您自己的站点,则需要设置 Apache 以根据文件扩展名提供适当的 MIME 类型。

如果是第三方网站,我不确定您是否可以依赖哑剧类型,因为它们可以提供他们想要的任何服务。 最好的办法可能是只获取文件的前几行并检查根元素是否为 xsl。

Are you using this to access third-party sites or a site that you configure yourself? If it's your own site, you'd need to set up Apache to serve the appropriate mime types depending on the file extension.

If it's third party sites, I'm not sure you can rely on the mime types, since they could serve whatever they want. Best bet is probably to just get the first few lines of the file and check that the root element is xsl.

枫以 2024-08-05 20:39:09

对于 PHP 5,不同的方法:

  1. 您可以尝试在 XSLTProcessor< 中加载样式表/a>. 如果样式表不正确,可能会引发异常
  2. (更好的恕我直言)验证 针对其模式的 XSL 样式表

Different approach, for PHP 5:

  1. You could try to load the stylesheet in an XSLTProcessor. Maybe an exception is thrown if the stylesheet is incorrect
  2. (Better IMHO) Validate the XSL stylesheet against its schema
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文