C# 操作超时正常还是错
net(客户端)调用IIS(服务端)出现503后,就报操作超时错误
服务端环境:
IIS
客户端环境:
windowsxp + iis + .net
调用时出现如下错误:
System.Net.WebException: 远程服务器返回错误: (503) 服务器不可用。
在 System.Net.HttpWebRequest.GetResponse()
在 TestWebRequest.WebMessage.SendRequest(Byte[] data, String urlStr)
接着就出现如下错误:
System.Net.WebException: 操作超时
在 System.Net.HttpWebRequest.GetRequestStream()
最后一直是这个错误
System.Net.WebException: 操作超时
在 System.Net.HttpWebRequest.GetRequestStream()
当服务器恢复正常时,访问已经是200时,这个线程还是返回操作超时,经过N多测试,最后如下一行完美解决:
myRequest.ServicePoint.Expect100Continue = false;
修改后的方法为:
1 public byte[] SendRequest(byte[] data, string urlStr)
2 {
3 try
4 {
5 Stream streamSend = null;
6 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(urlStr);
7 myRequest.Method = "POST";
8 myRequest.ContentType = "text/xml";
9 myRequest.Accept = "*/*";
10 myRequest.Timeout = 2000;
11 myRequest.UserAgent = "Mozilla-Firefox-Spider(Wenanry)";
12 myRequest.ContentLength = data.Length;
13 //这个在Post的时候,一定要加上,如果服务器返回错误,他还会继续再去请求,不会使用之前的错误数据,做返回数据
14 myRequest.ServicePoint.Expect100Continue = false;
15
16 HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
17 myRequest.CachePolicy = noCachePolicy;
18
19 try
20 {
21 streamSend = myRequest.GetRequestStream();
22 streamSend.Write(data, 0, data.Length);
23 streamSend.Close();
24 }
25 catch (WebException wex)
26 {
27 log.Debug("WebException=" + wex.ToString() + ",wex.Status=" + wex.Status);
28 if (streamSend != null)
29 streamSend.Close();
30 streamSend = null;
31 myRequest = null;
32 return null;
33 }
34 catch (Exception ex)
35 {
36 log.Debug("GetRequestStream=" + ex.ToString());
37 if (streamSend != null)
38 streamSend.Close();
39 myRequest = null;
40 return null;
41 }
42
43 byte[] byteArr = new byte[256];
44 Stream streamRequest = null;
45 try
46 {
47 streamRequest = myRequest.GetResponse().GetResponseStream();
48 }
49 catch (Exception httpex)
50 {
51 log.Debug("SendRequest=" + httpex.ToString());
52 if (streamRequest != null)
53 streamRequest.Close();
54 myRequest = null;
55 return null;
56 }
57 Bytes bytes = new Bytes();
58 int count = streamRequest.Read(byteArr, 0, 256);
59 while (count > 0)
60 {
61 bytes.writeByteArr(Bytes.byteSub(byteArr, 0, count));
62 count = streamRequest.Read(byteArr, 0, 256);
63 }
64 streamRequest.Close();
65 return bytes.getByte;
66 }
67 catch (Exception eee)
68 {
69 log.Debug("eee=" + eee.ToString() + eee.Source + eee.StackTrace);
70 }
71 return null;
72 }
太晚了,睡觉。
C# 操作超时正常还是错的更多相关文章
- ENSP NE40E 报错(NE1启动操作超时,请检查与服务器链接后重试!)
前言:某网友淘宝找我咨询NE40E启动失败的问题,事后我整理的处理过程,供各位同行参考. 系统版本:windows 10 软件版本: ENSP:V100R003C00 virtual BOX:5.2. ...
- wcf 请考虑增加操作超时
发送到 net.tcp://192.168.1.18:8732/CallbackService 的请求操作在配置的超时(00:00:59.9879994)内未收到回复. 分配给此操作的时间可能已经是更 ...
- C#用WebClient下载File时操作超时的问题
原文:C#用WebClient下载File时操作超时的问题 今天很SB,被这个问题卡住了.那段代码也是网上找的.结果发现只能下载一个文件,第二次下载的时候就会出现“操作超时”的问题. 这个是原代码: ...
- 同花顺核新下单程序的"界面不操作超时时间"的设定
"界面不操作超时时间"的设定 同花顺核新下单程序的'界面不操作超时时间'的设定 系统> 系统设置> 界面设置> 界面不操作超时时间(分): 在这个输入框里填上个3 ...
- HttpWebRequest中GetResponse或者说GetRequestStream偶尔超时,或者是各种操作超时造成的假死的一些解决方案
今天用了将近一天的时间来查找这个问题的存在,不停的百度查找原因测试原因,发现解决方案很是简单,不过最好还好哦啊都解决了,在这里纪录一下,希望可以帮到你们 payload = System.Text.E ...
- chrome无法登陆账号,显示操作超时的解决方案
起因 今天重装了下windows操作系统,准备登陆chrome浏览器,以同步各种插件(你懂的),结果是...无法登陆账号,显示操作超时,真是无语了. 碰到了这个问题第一个直觉是:FQ.突然想到如果修改 ...
- C# post数据时 出现如下错误: System.Net.WebException: 操作超时
net(客户端)调用IIS(服务端)出现503后,就报操作超时错误 问题描述: 服务端环境: IIS 客户端环境: windowsxp + iis + .net 调用时出现如下错误: System.N ...
- delete操作字符串会报错吗?
其实是不会的."delete只能对对象属性进行操作"的说法是错误的,严谨来说,delete可以对任意变量类型进行操作,只不过只有对对象的属性才能操作成功,对其他变量类型操作失败罢了 ...
- windows下Eclipse操作MapReduce例子报错:Failed to set permissions of path: \tmp\hadoop-Jerome\mapred\staging\
windows下Eclipse操作MapReduce例子报错: 14/05/18 22:05:29 WARN util.NativeCodeLoader: Unable to load native- ...
随机推荐
- Largest Divisible Subset -- LeetCode
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- UOJ Rounds
UOJ Test Round #1 T1:数字比大小的本质是按(长度,字典序)比大小. T2:首先发现单调性,二分答案,用堆模拟,$O(n\log^2 n)$. 第二个log已经没有什么可优化的了,但 ...
- 5.10(java学习笔记)容器的同步控制与只读设置
1.容器的同步控制 像我们平常使用的容器有些是不同步的即线程不安全,例如HashMap等,在多线程时可能出现并发问题. 而有些容器又是同步的,例如Hashtable. 有些时候我们需要将这些不同步的容 ...
- Scala学习总结
1)将Array转化为String,toStrings()方法应该是序列化了的. scala> val args = Array("Hello", "world&q ...
- 将html文档转成pdf
(1)使用场景:在项目中使用到了合同,只有在合同的头部,是不相同的.在合同的主体部分都是相同的,因此就把他放到了模板(html文件)里面. 在用户线上签约完成之后,可以将pdf版的合同下载. (2)需 ...
- 网络编程-UDP
代码部分--UDP传输 * 1.发送Send * 创建DatagramSocket, 随机端口号 * 创建DatagramPacket, 指定数据, 长度, 地址, 端口 * 使用DatagramSo ...
- PHP将字符串首字母大小写转换
每个单词的首字母转换为大写:ucwords() <?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! $bar = ...
- SQL Server 笔试题总结
1:编写Sql语句,查询id重复3次以上的条目,表为Pram(id,name) 先看建立的表: SQL语句: 直接使用一个子查询即可 select * from Pram where id in(se ...
- 关于BOM UTF8
这三篇可以看下: http://www.zhihu.com/question/20167122 http://www.cnblogs.com/DDark/archive/2011/11/28/2266 ...
- [ubuntu Setup] ubuntu 14.10 安装 JDK
from : http://www.cnblogs.com/plinx/archive/2013/06/01/3113106.html 1.到 Sun 的官网下载 http://www.oracle ...