如何获得适用于 IIS 6、7 和 Apache 的标头?

发布于 2024-07-09 01:30:46 字数 1008 浏览 8 评论 0原文

我正在尝试获取一个可与 Apache、IIS 6 和 IIS 7 一起使用的标头。我不会在这里详细说明其原因。 只能说,这并不像我想象的那么容易:-)

无论如何,这个问题与 NPH 有关。 在我们的代码(最初是为 IIS 6 编写的)中,我们

use CGI qw(:standard);

print "HTTP/1.0 200 OK\n";

print header;

在每个 cgi 脚本的顶部都有; 我读到这就是你告诉 IIS 你想要 NPH 的方式。

Apache 使用文件名来查看输出是否为 nph(nph- 必须是文件名的开头),所以我所做的(在 IIS 6 和 Apache 中都有效)如下:

use CGI qw(:standard);
print header('text/html', '200 OK');

有趣的是,IIS 7 似乎需要 NPH,所以如果我不这样做

use CGI qw(:standard -nph);

或者

print "HTTP/1.0 200 OK\n";

print header('text/html', '200 OK'); #parameters are apparently optional 

浏览器尝试对文件做一些奇怪的事情,因为它没有获取 mimetype。

另请注意:IIS 6 和 7 完全不需要打印任何标头,但 Apache 不喜欢这样。

不管怎样,现在最好的事情就是

use CGI qw(:standard);
print header('text/html', '200 OK');

在 IIS 7 中以某种方式工作。有谁知道我该怎么做? 我不知道服务器配置的所有详细信息,但如果您告诉我如何获取您可能需要的任何详细信息,我就可以做到。

不管怎样谢谢!

I am trying to get a header that will work with Apache, IIS 6, and IIS 7. I won't go into the reason for that here. Let's just say that it's not as easy as I thought it would be :-)

Anyway, the problem has something to do with NPH. In our code (originally written for IIS 6) we have

use CGI qw(:standard);

print "HTTP/1.0 200 OK\n";

print header;

at the top of every cgi script; I read that this is how you tell IIS that you want NPH.

Apache uses the filename to see if the output is nph (nph- must be the beginning of the filename) so what I did (which works in both IIS 6 and Apache) is the following:

use CGI qw(:standard);
print header('text/html', '200 OK');

IIS 7, interestingly, seems to require NPH, so if I don't either do

use CGI qw(:standard -nph);

or

print "HTTP/1.0 200 OK\n";

print header('text/html', '200 OK'); #parameters are apparently optional 

the browser tries to do something weird with the file, since it doesn't get the mimetype.

Also note: IIS 6 and 7 are ok without printing any header at all, but Apache doesn't like that.

Anyway, the best thing right now would be to make

use CGI qw(:standard);
print header('text/html', '200 OK');

somehow work in IIS 7. Does anyone know how I can do that? I don't know all the details for our server configuration, but if you tell me how to get any details you might need, I can do that.

Thanks either way!

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

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

发布评论

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

评论(2

抚笙 2024-07-16 01:30:46

我只是创建一个子例程,根据服务器执行正确的操作。 您知道在每种情况下必须做什么,所以在这种情况下就这样做。

另一个选项是修补 CGI.pm 以通过查看服务器类型正确设置其 $CGI::NPH 变量。 CGI.pm 已经具备了基础知识。 修复该问题后,提交补丁。

祝你好运 :)

I'd just create a subroutine that does the right thing depending on the server. You know what you have to do in each case, so just do that in that case.

The other option is to patch CGI.pm to set its $CGI::NPH variable correctly by looking at the server type. CGI.pm already has the basics there. Once you fix that, submit a patch.

Good luck :)

三五鸿雁 2024-07-16 01:30:46

Brian(和其他人)告诉我编写一个子程序来执行正确的操作。 希望这对其他人有帮助!

sub header {
    return (($ENV{PERLXS})?"HTTP/1.0 200 OK\r\n":"").CGI->header(@_);
}

Brian (and others) have told me to write a subroutine that would Do The Right Thing. Hope this helps someone else!

sub header {
    return (($ENV{PERLXS})?"HTTP/1.0 200 OK\r\n":"").CGI->header(@_);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文