XMLHttpRequest在6次后停止发送

时间:2016-04-26 17:54:08

标签: javascript vb.net google-chrome google-chrome-extension

chrome.browserAction.onClicked.addListener(function (tab) {
                                var httpReq = new XMLHttpRequest();
                                httpReq.addEventListener("error", function() { console.error(httpReq.status + " " + httpReq.statusCode); })
                            var dotNetUrl = "http://localhost:60005/";
                            httpReq.open("POST", dotNetUrl)
                            httpReq.send("HELLO");
})

点击6次后,请求停止发送。如果我重新加载我的扩展程序或服务器,我可以再发送6个。我的VB.NET应用程序正在另一端接收。

Public Async Sub CallListener()
    Await Threading.Tasks.Task.Run(Sub() Listener())
End Sub

Public Sub Listener()
    Try
        While (True)
            Dim t = hListener.GetContextAsync()
            Dim context As HttpListenerContext = t.Result()
            Dim request As HttpListenerRequest = context.Request()

            Dim stream As IO.Stream = request.InputStream
            Dim reader As IO.StreamReader = New IO.StreamReader(stream)
            Dim streamRTE As String = reader.ReadToEnd()

            stream.Close()
            reader.Close()

            RaiseEvent DataReceived(streamRTE)
        End While
    Catch ex As Exception
    End Try
End Sub

我构建了一个测试VB.NET客户端,看看它是否是我的服务器,但事实并非如此。客户端可以发送任意数量的服务器,服务器也会收到它。也许有些不兼容?我只是希望我的Google Chrome扩展程序将数据发送到我的.NET应用程序。我的扩展程序不需要接收任何内容。

1 个答案:

答案 0 :(得分:1)

这是由服务器缺乏响应引起的。

VB代码

Dim response As HttpListenerResponse = context.Response()
Dim responseString As String = ""
Dim b As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
Dim outputStream As IO.Stream = response.OutputStream
outputStream.Write(b, 0, b.Length)
outputStream.Close()

现在浏览器应该可以发出更多请求,因为没有待处理的请求,因为服务器响应。