2013-10-12 36 views
2

我製作了一個動態博客引擎,其中多位作者可以發佈文章。413完整HEAD錯誤

筆者去的地方,他通過一個基於AJAX請求輸入'文章「的描述」和「全篇」三個<textarea> 然後我存儲在3個變量的所有值並將其存儲在數據庫中的網頁。

問題: HttpServerRequest太大,它提供了413滿頭錯誤,並且請求不通過。

驗證碼:

的HTML:

<div class="container"> 
     <h4 class="text-left">Title:</h4> 
     <textarea id="title" rows="2" cols="" ></textarea> 
     <br /> 
     <h4 class="text-left">Description:</h4> 
     <textarea id="description" rows="5" cols="" ></textarea> 
     <br /> 
     <h4 class="text-left">Article:</h4> 
     <textarea id="article" rows="40" cols="" onkeyup="replaceWordChars(this.value)"></textarea> 
     <br /> 

     <div class="publish btn">Publish</div> 
     <br /> 
     <br /> 
    </div> 

腳本:

<script> 
    $(function(){ 
     $('.publish').click(function(){ 
      title = $('#title').val(); 
      description = $('#description').val(); 
      article = $('#article').val(); 

      $.ajax({ 
       type:  "get", 
       url:  "/articles", 
       data:  {action:'add', title:title, description:description, article:article}, 
       success: function(code) 
       { 
          alert("published"); 
          window.location="dashboard.jsp"; 
       } 

      }).error(function(){ alert("error"); }) 
      .complete(function(){ alert("complete"); }); 

     }); 

    }); 
    </script> 

的錯誤:

"NetworkError: 413 FULL head - http:///articles?action=add&title=blah&..........gs.%0A%0A&userId=1"

問題:

是否有其他方式發送大型服務器請求? 我也讀過谷歌,我們可以改變大小,以匹配巨大的請求?

答案在Java,HTML,JavaScript的(或)jQuery的是優選

EDIT我讀here,我們可以設置在插頭端子請求的大小限制?我如何在GAE中做到這一點?

+0

也許websocket!? – 2013-10-12 12:12:32

+0

@ user2511414不,這對單個請求來說太過分了。無論如何,GAE *甚至不支持websocket。 – hexafraction

+0

我還沒有見過用get方法發送大數據!也許你需要以POST方式發佈數據。 – 2013-10-12 12:26:49

回答

5

不要對大參數使用HEAD或GET。這些只應用於冪等請求(重複它不會破壞任何內容),並且請求只能檢索數據(即搜索或過濾產品數據庫)。

使用POST請求,而不是:

<script> 
    $(function(){ 
     $('.publish').click(function(){ 
      title = $('#title').val(); 
      description = $('#description').val(); 
      article = $('#article').val(); 

      $.ajax({ 
       type:  "post", 
       url:  "/articles", 
       data:  {action:'add', title:title, description:description, article:article}, 
       // .... skipped unchanged lines 
    </script> 

這是一個單行的變化。

在服務器上,確保在servlet中使用doPost()而不是doGet()。你可以用類似的方式獲取參數。

0

在我的情況下,HEADER已滿,因爲cookie值對於SESSIONID來說太大。我刪除了該網站的所有cookie,它工作。