XmlHtt prequest在Android的双张贴问题问题、XmlHtt、prequest、Android

2023-09-06 15:11:22 作者:昨夜西风

我在网络服务器实现了一个简单的AJAX后(通过JS XmlHtt prequest对象)的网页。

I have implemented a simple AJAX post (through JS XmlHttpRequest object) to a web page in webserver.

不过,我在Android操作系统2.X的默认浏览器观察到一个奇怪的症状/问题 也就是说,如果由于某种原因,有足够长的时间延迟的网络服务器来返回一个响应(可以通过在网页硬编码的Thread.Sleep模拟),浏览器将自动重新交相同的请求到网络服务器再次在等待。

However, I observed a weird symptom/issue on default browser in Android OS 2.X That is, if for some reason there is long enough delay for the webserver to come back with a response (can be simulated by hard coding Thread.Sleep in the web page), the browser would automatically re-post the same request to the webserver again during the wait.

<script type="text/javascript">
     $(document).ready(function() {
        PerformRequest();
    });

    function PerformRequest() {
        appendMessage('PerformRequest... ');

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("POST", "http://localhost/DelaySite/Default.aspx", true);
        xmlhttp.onreadystatechange = function()
            {
            appendMessage("xmlhttp.readyState: " + xmlhttp.readyState, true);
            appendMessage("xmlhttp.status: " + xmlhttp.status, true);
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                // successful response
                }
            }
        xmlhttp.send();
    }
</script>

有没有人见过这个问题,Android的浏览器?如果是这样,没有人知道原因吗?

Has anyone seen this issue in Android browser? If so, does anyone know the cause?

是不是这被认为是一个安全问题?考虑的情况下,其中每个请求可以可能作出两次之间是否有移动和主机足够长的网络延迟。

Isn't this to be considered as a security issue? Consider case where each request can be possibly made twice if there is long enough network delay between mobile and the host.

不过,我不能在ICS复制这个问题,只能在Android操作系统2.X

However, I can't replicate this issue in ICS, only in Android OS 2.X

问候, 奥利弗

Regards, Oliver

推荐答案

我遇到了同样的问题,但是我发现,这不是具体到本机浏览器(试图与天火藏汉)。在这三个Android手机的一再要求下之前的延迟是(一致):

I encountered the same issue, however I discovered that it wasn't specific to the native browser (tried with Skyfire aswell). On these three Android phones the delay before the repeated request was (consistently):

在三星Galaxy S2:30秒 的HTC Desire:60秒 HTC感觉:60秒

我问身边的工作意见,我得到的回应是使异步请求:

I asked around at work for advice and the response I got was to make the request asynchronous:

使服务器处理请求的异步和POST请求立即用201响应包括位置指向状态页/ URL表示POST请求的进度。客户端可以检索与一个GET到该URL的请求的进度。的