2011-05-27 57 views
12

我在MSIE8中遇到了一些奇怪的HTTP狀態碼問題。爲什麼MSIE 8報告12150的HTTP狀態碼?

我發送一個HTTP GET到以下網址:

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

從小提琴手,我可以看到,我得到以下原始響應:使用以下

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 ...但標題看起來不錯。

我無法弄清楚這裏有什麼問題......有人看到我可能忽略的任何東西嗎?

+0

真是奇怪的問題。嘗試僅打印標題「Location ...」,但使用完整URL - http://example.com/cgi-bin ... – silex 2011-05-27 20:57:09

回答

4

問題解決了!

這個錯誤是標題生成。

生成的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 
+1

標準要求位置URI是絕對的,即使它們傾向於以相對方式工作。你可以用CGI中的'url()'方法/函數來生成這些。 – Ashley 2011-05-27 23:42:25

+4

爲了更加準確:它被「解釋爲在身體中」,因爲你把它放在身體裏。 '$ cgi-> header'打印*所有*標題並結束它們:) – hobbs 2011-05-28 01:27:39