Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试在不存在的网络连接上执行操作,错误代码1229_C#_Html - Fatal编程技术网

C# 尝试在不存在的网络连接上执行操作,错误代码1229

C# 尝试在不存在的网络连接上执行操作,错误代码1229,c#,html,C#,Html,只要在一个简单的HttpListener上工作,这个异常就会突然出现 尝试在不存在的网络连接上执行操作 在几个小时内寻找解决方案,但找不到。当我从网页向HttpListener提交数据时,代码就崩溃了。 有人能告诉我如何解决这个问题吗 代码如下: C# HTML <html> <head> <title>http</title> <meta charset="utf-8">

只要在一个简单的HttpListener上工作,这个异常就会突然出现

尝试在不存在的网络连接上执行操作

在几个小时内寻找解决方案,但找不到。当我从网页向
HttpListener
提交数据时,代码就崩溃了。 有人能告诉我如何解决这个问题吗

代码如下:

C#

HTML

<html>
    <head> 
        <title>http</title>
        <meta charset="utf-8">
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <style>

            body{
        font-size: 12px;
        font-family: Arial;
        }

        legend{
            font-weight: bold;
            font-size: 14px !important;
        }


        fieldset{
            width:200px;
            margin: 0;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-right: -50%;
            transform: translate(-50%, -50%) }

        .wrapper{
            width: 100%;
        }

        </style>


        <script language="javascript">

        //<!-- Create variable timer -->
            var timer;


        //<!-- Create Fucntion CheckOne -->
        /* 
            Wannneer de functie aangroepen word, word eerst de timeout van de variable timer geleegd.
            Daarna word er een timeout ingesteld van 2000 (2sec). Die timeout wordt ingeschakeld nadat het textveld niet meer actief beschouwd word(niet meer gebruikt word, de focus blijft wel op het veld.).
            Na die 2 seconden krijgt de volgende textbox de focus met de zelfde manier maar onder een andere functie.
            Zodra hier ook de 2 seconden om zijn verspringt de focus weer maar nu naar een sumbit (verzenden) knop. Dit is gedaan omdat je dan makkelijk op een OK knop kan drukken op het apparaat.
        */

            function CheckOne() {
                 clearTimeout(timer)
                 timer = setTimeout(function(){
                     document.getElementById("two").focus();
                     //clearTimeout(timer);
                 }, 750)
            }

            function CheckTwo(){
                clearTimeout(timer);
                timer = setTimeout(function(){
                     document.getElementById("sub").focus();
                 }, 750)
            }


        </script> 
        



    </head> 

    <body> 

    <div class="wrapper"> 
        <fieldset> 
            <legend>HttpListener </legend><br/> 
            <form id="searchForm" action="http://localhost:8100/myForm/doSomething" >
                Locatienummer: <br />
                <input type="text" id="one" onkeyup="CheckOne()" name="locatienummer"><br />
                Bonnummer: <br />
                <input type="text" id="two" onkeyup="CheckTwo()" name="bonnummer"><br /><br />
                <input id="sub" type="submit" value="Verzenden" />
            </form> 
        </fieldset> 
    </div> 
    <!-- Include the needed files--> 

        <script>
    $("#searchForm").submit(function (event)
    {
        // Stop form from submitting normally
        event.preventDefault();

        // Get some values from elements on the page:
        var $form = $(this),

        locatieValue = $form.find("input[name='locatienummer']").val(),
        bonValue = $form.find("input[name='bonnummer']").val(),

        url = $form.attr("action");

        // Send the data using post
        $.post(url, { a: locatieValue, b: bonValue });

    });
        </script>

    </body> 
</html>

http
身体{
字体大小:12px;
字体系列:Arial;
}
传奇{
字体大小:粗体;
字体大小:14px!重要;
}
字段集{
宽度:200px;
保证金:0;
位置:绝对位置;
最高:50%;
左:50%;
保证金权利:-50%;
转换:转换(-50%,-50%)}
.包装纸{
宽度:100%;
}
//
无功定时器;
//
/* 
一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字,一个字。
Daarna word er een 2000(2秒)。在文本中输入超时单词,并将其激活为单词(niet-meer-gebruikt单词,并将其聚焦到其他级别)。
第二次会议的焦点文本框会议是在会议结束后召开的。
Zodra在萨姆比特(verzenden)的诺普(knop)附近的2名二等兵和2名二等兵。这是一个很好的解决方案,是一个很好的解决方案。
*/
函数CheckOne(){
清除超时(计时器)
计时器=设置超时(函数(){
document.getElementById(“两个”).focus();
//清除超时(计时器);
}, 750)
}
函数CheckTwo(){
清除超时(计时器);
计时器=设置超时(函数(){
document.getElementById(“sub”).focus();
}, 750)
}
HttpListener
位置枚举器:

邦努默:


$(“#搜索表单”).submit(函数(事件) { //阻止表单正常提交 event.preventDefault(); //从页面上的元素获取一些值: var$form=$(此), locatieValue=$form.find(“输入[name='locatienummer']”)。val(), bonValue=$form.find(“输入[name='bonnumer']”)。val(), url=$form.attr(“操作”); //使用post发送数据 $.post(url,{a:locatieValue,b:bonValue}); });
本质上,您的问题被触发是因为您在完成请求流的处理之前正在写入响应流。如果您对代码进行重新排序以处理请求,那么在您开始尝试编写响应之前,它将起作用。您可能需要重新访问代码,但本质上将其更改为以下内容将使您继续:

HttpListenerContext context = listener.GetContext();
HttpListenerRequest request= context.Request;
HttpListenerResponse response = context.Response;

// Process Request **First**
String url = request.RawUrl;
String[] queryStringArray = url.Split('/');
String postedtext = GetPostedText(request);                   

// Process Response **Second**
string html = Properties.Resources.index;
byte[] webPageBuffer = Encoding.UTF8.GetBytes(html);

response.ContentLength64 = webPageBuffer.Length;
ouputStream = response.OutputStream;
ouputStream.Write(webPageBuffer, 0, webPageBuffer.Length);

ouputStream.Flush();

/* etc */

今天我遇到了同样的异常,导致我的情况的原因是我在尝试写入
HttpResponseStream
之前停止了侦听器。诀窍是总是在获取侦听器上下文后立即编写响应。

检查防病毒或防火墙阻止。同时检查,我已经检查了我的防火墙和防病毒软件,但我认为代码中有一些东西。1229与tcp协议有关,我有同样的问题,这个异常发生在哪一行?我注意到输出流没有关闭。您在StartListening函数中分配了两次OutStream,但它只关闭了一次,我不确定这是否解决了您的问题。但这是你应该考虑的问题。在我的例子中,问题不是命令(可能!)。由于我的应用程序资源有限,一次只能处理一个请求。每次处理大约需要10秒钟,如果在此期间由于任何原因客户端断开连接,则我们没有输出响应。我的假设正确吗?为了确保可以写入流,我在代码中添加了if(outputStream.CanWrite),正好是写入前的那一行。
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request= context.Request;
HttpListenerResponse response = context.Response;

// Process Request **First**
String url = request.RawUrl;
String[] queryStringArray = url.Split('/');
String postedtext = GetPostedText(request);                   

// Process Response **Second**
string html = Properties.Resources.index;
byte[] webPageBuffer = Encoding.UTF8.GetBytes(html);

response.ContentLength64 = webPageBuffer.Length;
ouputStream = response.OutputStream;
ouputStream.Write(webPageBuffer, 0, webPageBuffer.Length);

ouputStream.Flush();

/* etc */