我是用循环来调用的.不是马上出现,出现的时间不定...奇怪了string loginUrl = "http://192.168.1.101/DoServer.Class.php";
Encoding encoding = Encoding.GetEncoding("UTF-8"); HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, null, null, encoding, null);
//response.ti
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String retValue = sr.ReadToEnd(); sr.Close(); return retValue;System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
at System.Net.HttpWebRequest.GetResponse()
at WindowsEE.HttpWebResponseUtility.CreatePostHttpResponse(String url, IDictionary`2 parameters, Nullable`1 timeout, String userAgent, Encoding requestEncoding, CookieCollection cookies)
at WindowsEE.MethodOption.common(IDictionary`2 parameters)
at WindowsEE.Main.timer2_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Encoding encoding = Encoding.GetEncoding("UTF-8"); HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(loginUrl, parameters, null, null, encoding, null);
//response.ti
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String retValue = sr.ReadToEnd(); sr.Close(); return retValue;System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
at System.Net.HttpWebRequest.GetResponse()
at WindowsEE.HttpWebResponseUtility.CreatePostHttpResponse(String url, IDictionary`2 parameters, Nullable`1 timeout, String userAgent, Encoding requestEncoding, CookieCollection cookies)
at WindowsEE.MethodOption.common(IDictionary`2 parameters)
at WindowsEE.Main.timer2_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
解决方案 »
- C#调用c++dll下函数参数问题
- static 声明属于类型本身而不是属于特定对象的成员,究竟是什么意思,怎么用的啊,高手来指点下小弟
- 如何用C#修改文件夹的权限?
- 在win2003 server中,webbrowser加载不了本地png图片
- fastreport小数显示问题
- C# 怎么对注册表进行添加和删除的操作
- 用RejectChanges居然退出了ShowDialog打开的窗口,谁知道是怎么回事吗?
- 急:c# 调用 managed wrapper 的问题
- 正则表达式 C#关键字-在线等待
- 我想把一个Delphi控件移植到C#中,但是我对C#不熟,希望大家给我提出一点意见,提意见者有分.
- 外网IP很容易获取到【有代码】,但怎样获取当前(有几个网卡)网卡的内网IP呢?
- Excel导数据导出来格式不对
问题出在这,你为什么要循环调用呢?来不及反应,肯定挂了。类似于ddos攻击,服务器受不了,就停止服务了。
也就是循环里面,判断当满足条件,就新建一个线程去提交数据,并且取得返回值.
有例子最好
不是要长时间保持??? 这是服务器主动断开的吧,你保持不了的吧
System.Windows.Forms.Application.ThreadExceptionEventHandler 捕获,在界面上给用户一个友好提示,然后用户“知道了”之后程序就继续执行下去就好了。而如果是静默的、轮询的任务,你自己捕获异常然后过一会儿重新开始任务就行了。凡是涉及到互联网通讯的程序,都可能随时抛出异常。因此考虑到这个处理就行了。
request.ProtocolVersion = HttpVersion.Version10;
你在多线程里new这个对象,调用他的方法吧.避免多线程调用太频繁,服务器有链接时长限制