简体   繁体   English

字符串超出Ajax POST长度限制

[英]String exceeding ajax POST length limit

I'm trying to send an array from my jsp to my Servlet via ajax POST request. 我试图通过ajax POST请求将数组从我的jsp发送到我的Servlet。 My array has a few objects with many fields. 我的数组有一些带有许多字段的对象。 If I try to send and array with 11 objects - using JSON.stringify - it works OK (the array is received on server-side), but the problem happens when I try to send an array with 12+ objects. 如果我尝试使用JSON.stringify发送和包含11个对象的数组,则可以正常工作(在服务器端接收到数组),但是当我尝试发送包含12个以上对象的数组时,就会出现问题。 The error is: 400 Bad Request and looking with Google Chrome Debugger, I can find this error: fluxos:(unable to decode value) where fluxos is the name of my array. 错误是: 400 Bad Request ,使用Google Chrome调试器查看时,我发现以下错误: fluxos:(unable to decode value) ,其中fluxos是我的数组名称。

RELEVANTE PART OF CODE: 代码的高级部分:

for(var i=0; i<numberOfConnections; i++) {
    fluxo = criaEstruturaFluxo(i);
    fluxos.push(fluxo);
}

$.ajax({
    type: "POST", 
    url: 'Servlet?fluxos='+JSON.stringify(fluxos),
            success: function (data) {
            alert('success');
    }
});

...
function criaEstruturaFluxo(i) {
    ...
    ...
    var fluxo = {
      xOrigem: xOrigem, 
      yOrigem: yOrigem,
      xDestino: xDestino,
      yDestino: yDestino,
      codWorkflow: codWorkflow,
      acaoAvanco: acaoAvanco,
      codAtividadeOrigem: codAtividadeOrigem[1],
      codAtividadeDestino: codAtividadeDestino[1],
      numero: numero,
      nomeAtividadeOrigem: nomeAtividadeOrigem,
      nomeAtividadeDestino: nomeAtividadeDestino,
      codConexao: codConexao,
      tipoOrigem: tipoOrigem,
      tipoDestino: tipoDestino,
      xFluxoOrigem: xFluxoOrigem,
      yFluxoOrigem: yFluxoOrigem,
      xFluxoDestino: xFluxoDestino,
      yFluxoDestino: yFluxoDestino,
      deletarArquivo: deletarArquivo,
      ultimaConexao: ultimaConexao,
      caminhoArquivo: caminhoArquivo,
      xTela: xTela,
      yTela: yTela
    };

    return fluxo;
}

My encoded array has 8000+ characters length and because of that, I think it's exceeding the max length a POST request can handle... Is that possible or might be something on the code that I'm sending to my Servlet? 我的编码数组具有8000+个字符的长度,因此,我认为它超出了POST请求可以处理的最大长度...是否有可能或可能是我发送给Servlet的代码中的某些内容?

Your url is very long. 您的网址很长。 In theory that shouldn't cause any problems, but there's a practical limit that depends on the server and proxies that you use. 从理论上讲,这不会引起任何问题,但是有一个实际的限制,取决于您使用的服务器和代理。 Send the data on the body of the request and not on the url. 将数据发送到请求的正文中,而不发送到url上。

Agree with Andres & Luiggi. 同意Andres&Luiggi。 Here's what your modified code would look like: 修改后的代码如下所示:

$.ajax({
url: "Servlet",
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ "fluxos": fluxos }),
success: function(data) {
    alert("success");
}

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM