- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Apache 和 mod_perl 构建一个简单的异步 Web 服务。但是每次我尝试返回 HTTP 状态 202(已接受)时,我都会收到错误消息。
下面是一个非常简单的例子(非异步):
package MyHandler;
use Apache2::Const '-compile' => qw 'OK HTTP_ACCEPTED HTTP_OK';
use Apache2::RequestRec;
use CGI;
sub handler {
my $r = shift;
print "Hallo";
$r->content_type('text/plain');
$r->status(Apache2::Const::HTTP_ACCEPTED);
return Apache2::Const::HTTP_ACCEPTED;
}
1;
我得到了错误
在本地主机上的浏览器中调用处理程序,我得到了输出,但也有一个错误:
Hallo
Accepted
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
我也遇到了 Apache2::Const::HTTP_OK
的错误,唯一没有错误的是 Apache2::Const::OK
。
我的 apache 错误日志没有提到这个错误。
最佳答案
使用 mod_perl2 你不会返回 HTTP 状态代码(这就是为什么需要使用 $r->status()
所以设置 HTTP 状态代码的原因。
相反,您根据希望服务器执行的操作返回一个值。最常见的是 Apache2::Const::OK
。这告诉服务器您的处理程序已成功完成。如果我没记错的话,这个常量的整数值为 0
,而不是 200
。
从 mod_perl 处理程序返回 HTTP 状态代码将被解释为错误。
https://perl.apache.org/docs/2.0/user/handlers/intro.html#Handler_Return_Values
Different handler groups are supposed to return different values.
Make sure that you always explicitly return a wanted value and don't rely on the result of last expression to be used as the return value -- things will change in the future and you won't know why things aren't working anymore.
The only value that can be returned by all handlers is Apache2::Const::OK, which tells Apache that the handler has successfully finished its execution.
Apache2::Const::DECLINED is another return value that indicates success, but it's only relevant for phases of type RUN_FIRST.
HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.
关于apache - mod_perl 错误返回 202 Apache2::Const::HTTP_ACCEPTED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27025761/
我正在尝试确定客户的网络浏览器是桌面浏览器还是移动浏览器。我在网上找到了这段代码。 这是我收到错误的代码部分: if ((strpos(strtolower($_SERVER['HTTP_ACCEPT
是否可以仅使用 javascript 的 HTTP Accept header ?我知道使用 PHP 我会做这样的事情 $_SERVER['HTTP_ACCEPT'],但据我所知,javascript
我正在尝试使用 Apache 和 mod_perl 构建一个简单的异步 Web 服务。但是每次我尝试返回 HTTP 状态 202(已接受)时,我都会收到错误消息。 下面是一个非常简单的例子(非异步):
我注意到最新版本的 IE 8.0.6001.18372 发送了重复的 http_accept,如下所示: IE8 image/jpeg, image/pjpeg, image/gif, image/p
我有 Ruby on Rails 应用程序 (3.1rc4),而且我每天都在使用相同的用户代理 (Mozilla/4.0 (PSP (PlayStation Portable); 2.00)) 不断收
由于 ActionView::MissingTemplate,我的 rails 应用程序抛出异常-异常(exception)。这是因为请求有一个 http header ACCEPT值 : */* .
我是一名优秀的程序员,十分优秀!