我的ajax帖子向我的Heroku应用程序发出的请求在大约90%的通话中丢失了其发布数据。
出于安全原因,我正在使用GET并更改为POST。 GET请求已经工作了几个月。 POST请求在IDE中本地工作,并使用工头。但是当它移动到我的Heroku应用程序时,POST数据会在90%的调用中丢失。
我非常确定数据是否正确发送:
我将详细的传入请求数据转储到Papertrail日志。在这里,我可以看到数据消失了。内容长度表明请求数据应该在那里,但它已经消失了。
我正在使用的Ajax调用。我尝试过$ .post请求和非jquery ajax请求。我已尝试使用JSON.stringify对数据和许多不同的请求标头组合。
function doPostRequestWithDataV2(method, data) {
var methodName = "/call/echo";
var jqxhr = $.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: methodName,
data: {uuuuu: "ppppp"},
})
.done(function () {
var jsonString = jqxhr.responseText;
alert("All went well: " + jsonString);
})
.error(function () {
alert("Problem: " + jqxhr.responseText);
});
}
完全输出成功通话。粗体的重要区别。
Mar 07 07:29:18 my-fine-app app/web.1: FIRST TOUCH: Number of bytes 945 Mar 07 07:29:18 my-fine-app app/web.1: FIRST TOUCH: ########## Mar 07 07:29:18 my-fine-app app/web.1: POST /call/echo HTTP/1.1 Mar 07 07:29:18 my-fine-app app/web.1: Host: staging.kollektivafondval.se Mar 07 07:29:18 my-fine-app app/web.1: Connection: close Mar 07 07:29:18 my-fine-app app/web.1: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0 Mar 07 07:29:18 my-fine-app app/web.1: Accept: */* Mar 07 07:29:18 my-fine-app app/web.1: Accept-Language: en-US,en;q=0.5 Mar 07 07:29:18 my-fine-app app/web.1: Accept-Encoding: gzip, deflate Mar 07 07:29:18 my-fine-app app/web.1: Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Mar 07 07:29:18 my-fine-app app/web.1: X-Requested-With: XMLHttpRequest Mar 07 07:29:18 my-fine-app app/web.1: Referer: http://staging.kollektivafondval.se/debug/index.html Mar 07 07:29:18 my-fine-app app/web.1: Cookie: _ga=GA1.2.492366677.1421911589; __utma=33200548.492366677.1421911589.1425495130.1425495130.1; __utmc=33200548; __utmz=33200548.1425495130.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); cp=0; undefined=0; ptl=0; _gat=1 Mar 07 07:29:18 my-fine-app app/web.1: Pragma: no-cache Mar 07 07:29:18 my-fine-app app/web.1: Cache-Control: no-cache Mar 07 07:29:18 my-fine-app app/web.1: X-Request-Id: 17981145-acce-49bf-a5dd-e212a2a184ef Mar 07 07:29:18 my-fine-app app/web.1: X-Forwarded-For: 83.227.55.31 Mar 07 07:29:18 my-fine-app app/web.1: X-Forwarded-Proto: http Mar 07 07:29:18 my-fine-app app/web.1: X-Forwarded-Port: 80 Mar 07 07:29:18 my-fine-app app/web.1: Via: 1.1 vegur Mar 07 07:29:18 my-fine-app app/web.1: Connect-Time: 0 Mar 07 07:29:18 my-fine-app app/web.1: X-Request-Start: 1425709758119 Mar 07 07:29:18 my-fine-app app/web.1: Total-Route-Time: 0 Mar 07 07:29:18 my-fine-app app/web.1: Content-Length: 17 Mar 07 07:29:18 my-fine-app app/web.1: String=any+string Mar 07 07:29:18 my-fine-app app/web.1: ##########
缺少数据时的完整输出。粗体的重要区别。
Mar 07 07:29:15 my-fine-app app/web.1: ************************************************************ Mar 07 07:29:16 my-fine-app app/web.1: FIRST TOUCH: Number of bytes 928 Mar 07 07:29:16 my-fine-app app/web.1: FIRST TOUCH: ########## Mar 07 07:29:16 my-fine-app app/web.1: POST /call/echo HTTP/1.1 Mar 07 07:29:16 my-fine-app app/web.1: Host: staging.kollektivafondval.se Mar 07 07:29:16 my-fine-app app/web.1: Connection: close Mar 07 07:29:16 my-fine-app app/web.1: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:36.0) Gecko/20100101 Firefox/36.0 Mar 07 07:29:16 my-fine-app app/web.1: Accept: */* Mar 07 07:29:16 my-fine-app app/web.1: Accept-Language: en-US,en;q=0.5 Mar 07 07:29:16 my-fine-app app/web.1: Accept-Encoding: gzip, deflate Mar 07 07:29:16 my-fine-app app/web.1: Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Mar 07 07:29:16 my-fine-app app/web.1: X-Requested-With: XMLHttpRequest Mar 07 07:29:16 my-fine-app app/web.1: Referer: http://staging.kollektivafondval.se/debug/index.html Mar 07 07:29:16 my-fine-app app/web.1: Cookie: _ga=GA1.2.492366677.1421911589; __utma=33200548.492366677.1421911589.1425495130.1425495130.1; __utmc=33200548; __utmz=33200548.1425495130.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); cp=0; undefined=0; ptl=0; _gat=1 Mar 07 07:29:16 my-fine-app app/web.1: Pragma: no-cache Mar 07 07:29:16 my-fine-app app/web.1: Cache-Control: no-cache Mar 07 07:29:16 my-fine-app app/web.1: X-Request-Id: 16caf2b0-88a6-455b-ac03-71581920e1e5 Mar 07 07:29:16 my-fine-app app/web.1: X-Forwarded-For: 83.227.55.31 Mar 07 07:29:16 my-fine-app app/web.1: X-Forwarded-Proto: http Mar 07 07:29:16 my-fine-app app/web.1: X-Forwarded-Port: 80 Mar 07 07:29:16 my-fine-app app/web.1: Via: 1.1 vegur Mar 07 07:29:16 my-fine-app app/web.1: Connect-Time: 0 Mar 07 07:29:16 my-fine-app app/web.1: X-Request-Start: 1425709756264 Mar 07 07:29:16 my-fine-app app/web.1: Total-Route-Time: 0 Mar 07 07:29:16 my-fine-app app/web.1: Content-Length: 17 Mar 07 07:29:16 my-fine-app app/web.1: ##########
答案 0 :(得分:0)
EHH。我找到了自己问题的答案。我发现Heroku的路由层在发送标头后会暂停。所以我所要做的就是在读完所有字节后再添加2毫秒的休眠,然后从套接字再次读取。现在它完美无缺。