【问题标题】:Why does MSIE 8 report an HTTP status code of 12150?为什么 MSIE 8 报告 HTTP 状态代码 12150?
【发布时间】:2011-09-03 16:29:22
【问题描述】:

我在 MSIE8 中遇到了一些奇怪的 HTTP 状态代码问题。

我向以下 URL 发送 HTTP GET:

 /cgi-bin/objectBrowser/snap.pl?file_key=28

从 Fiddler 中,我可以看到我收到以下原始响应:

HTTP/1.1 302 Found
Date: Fri, 27 May 2011 20:24:38 GMT
Server: Apache/2.2.3 (Red Hat)
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 61

Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=32

这是使用以下 Perl 生成的:

print $cgi->header( -status => '302 Found' );
print "Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=$snap_key\n\n";

我正在使用 jQuery 来访问它,方式如下:

jQuery.ajax({
    type : "GET",
    url : "/cgi-bin/objectBrowser/file.pl?pmr=" + request.pmr
        + "&filename=" + request.filename,
    statusCode : {
        200 : function(file_info) {
            if (file_info.status == "parsing") {
            jQuery('div#updates').append('<div class="information">No snap yet, but file <i>has</i> been registered already.</div>');
            jQuery('div#updates').append('<div class="waiting">Awaiting job completion...</div>');
            jQuery.getJSON("/cgi-bin/objectBrowser/job.pl?file_key=" + file_info.file_key, function(job_info) {
            poll_for_job_completion(job_info);
                });
            } else {
            jQuery.ajax({
                type : "GET",
            url : "/cgi-bin/objectBrowser/snap.pl?file_key=" + file_info.file_key,
        statusCode : {
                302 : function(xhr) {
                jQuery('div#updates').append('<div class="information">Redirecting to snap</div>');
                            alert("302: "+ xhr.responseText);
                process_302(xhr.responseText);
                }
                    }
            });
        }
        },
        302 : function(xhr) {
            alert("302: "+ xhr.responseText);
        process_302(xhr.responseText);
        },
        404 : register_file
    }
});

最后,我有以下帮助调试:

jQuery('body').ajaxComplete(function(e,a,o) {
    console.log('Event: %o\nXHR: %o\nOptions: %o',e,a,o);
    console.log(o.url);
    console.log(a.status);
    console.log(a.responseText);
});

这一切在 Firefox 和 Chrome 中都可以正常工作,但在 MSIE 中,我通常会收到 302 的状态以响应我对 snap.pl 的请求,我得到的响应是 12150。我发现的最好的点击是MSDN,这表明这是ERROR_HTTP_HEADER_NOT_FOUND...但标题对我来说看起来不错。

我无法弄清楚这里出了什么问题...有人看到我可能忽略的任何东西吗?

【问题讨论】:

  • 真的很奇怪的问题。尝试仅打印标题“位置...”,但带有完整的 URL - example.com/cgi-bin...

标签: javascript jquery ajax perl http


【解决方案1】:

问题解决了!

错误是生成标头。

生成的 HTTP 标头中有一个很大的差距,MSIE8 将 Location 解释为在正文中,而不是在标头中。

通过使用

print $cgi->redirect( -uri =>  "/cgi-bin/objectBrowser/workWithSnap.pl?snapKey=$snap_key");

标头已正确创建,我再次得到明智的行为

HTTP/1.1 302 Found
Date: Fri, 27 May 2011 21:00:51 GMT
Server: Apache/2.2.3 (Red Hat)
Location: /cgi-bin/objectBrowser/workWithSnap.pl?snapKey=32
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8

【讨论】:

  • 标准要求位置 URI 是绝对的,即使它们倾向于作为相对的。您可以在 CGI 中使用 url() 方法/函数来稳健地生成它们。
  • 更准确地说:它被“解释为在体内”,因为你把它放在了体内。 $cgi-&gt;header 打印 所有 标题并结束它们 :)
猜你喜欢
  • 2015-09-18
  • 2021-11-17
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 2011-12-08
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
相关资源
最近更新 更多