2013-05-01 49 views
0

我正在通過node-webkit進行RSS聚合器工作,而且我偶然發現了一個看似隨機的請求數量的問題(以下代碼)將失敗,並顯示以下任一錯誤:HPE_INVALID_CONSTANT,ETIMEDOUT,EAGAIN和HPE_INVALID_HEADER_TOKEN。我已經對這些事件進行了排序。Node.js(node-webkit)錯誤使用http.get rss提要,HPE_INVALID_CONSTANT

我做了一個test.html文件儘可能多的相關性。只需將大量的網頁網址插入httpList即可使用。不過,要小心你使用的是什麼URL,你不想讓某些服務器崩潰!大約56的列表似乎對導致錯誤起作用。

順便說一下,這是真的很難重現,這意味着它必須是我可以改變我的目的。有時候,同一個URL會失敗,而在下一個階段它會起作用。另外我的網址已經失敗了,確實可以訪問(我用鉻打開它沒有問題)。

<!DOCTYPE html> 
<html> 
    <head> 
     <title>HTTP Get test</title> 
    </head> 
    <body> 
     <script> 
     var httpList = []; 
     var fromUrl = function(stringUrl) { 
      var http = require('http'); 
      var url = require("url"); 
      var urlData = url.parse(stringUrl); 
      var parser = window.document.createElement('a'); 
      parser.href = stringUrl; 
      var options = { 
       host: urlData.host, 
       path: urlData.path + urlData.search + urlData.hash 
      }; 

      var httpResponse = function(response) { 
       response.setEncoding('utf8'); 
       request.setSocketKeepAlive(true); 
       var str = ''; 

       response.on('data', function(chunk) { 
        str += chunk; 
       }); 

       response.on('end', function() { 
        request.setSocketKeepAlive(false); 
        console.log("url",stringUrl,"was successfully parsed"); 
       }); 
      } 

      var request = http.request(options, httpResponse) 
      request.on('error', function(e) { 
       if (e.code === "ENOTFOUND") { 
        console.error("The feed", stringUrl, "could not be fetched.") 
       } else { 
        console.log(e, e.message, stringUrl); 
       } 
      }); 
      request.end(); 
     }; 
     for(var i=0;i<httpList.length;i++) { 
      fromUrl(httpList[i]); 
     } 
     </script> 
    </body> 
</html> 

回答