天天看点

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

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()

最后一直是这个错误

当服务器恢复正常时,访问已经是200时,这个线程还是返回操作超时,经过N多测试,最后如下一行完美解决:

myRequest.ServicePoint.Expect100Continue = false;

public byte[] SendRequest(byte[] data, string urlStr)

2

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

{

3

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

try

4

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

5

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

Stream streamSend = null;

6

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(urlStr);

7

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.Method = "POST";

8

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.ContentType = "text/xml";

9

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.Accept = "*/*";

10

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.Timeout = 2000;

11

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.UserAgent = "Mozilla-Firefox-Spider(Wenanry)";

12

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.ContentLength = data.Length;

13

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

//这个在Post的时候,一定要加上,如果服务器返回错误,他还会继续再去请求,不会使用之前的错误数据,做返回数据

14

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

15

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

16

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

17

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest.CachePolicy = noCachePolicy;

18

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

19

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

20

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

21

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamSend = myRequest.GetRequestStream();

22

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamSend.Write(data, 0, data.Length);

23

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamSend.Close();

24

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

}

25

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

catch (WebException wex)

26

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

27

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

log.Debug("WebException=" + wex.ToString() + ",wex.Status=" + wex.Status);

28

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

if (streamSend != null)

29

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

30

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamSend = null;

31

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

myRequest = null;

32

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

return null;

33

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

34

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

catch (Exception ex)

35

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

36

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

log.Debug("GetRequestStream=" + ex.ToString());

37

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

38

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

39

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

40

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

41

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

42

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

43

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

byte[] byteArr = new byte[256];

44

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

Stream streamRequest = null;

45

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

46

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

47

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamRequest = myRequest.GetResponse().GetResponseStream();

48

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

49

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

catch (Exception httpex)

50

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

51

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

log.Debug("SendRequest=" + httpex.ToString());

52

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

if (streamRequest != null)

53

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

streamRequest.Close();

54

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

55

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

56

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

57

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

Bytes bytes = new Bytes();

58

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

int count = streamRequest.Read(byteArr, 0, 256);

59

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

while (count > 0)

60

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

61

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

bytes.writeByteArr(Bytes.byteSub(byteArr, 0, count));

62

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

count = streamRequest.Read(byteArr, 0, 256);

63

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

64

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

65

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

return bytes.getByte;

66

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

67

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

catch (Exception eee)

68

C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时
C# post数据时 出现如下错误: System.Net.WebException: 操作超时

69

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

log.Debug("eee=" + eee.ToString() + eee.Source + eee.StackTrace);

70

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

71

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

72

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<dl></dl>

<dd></dd>

.net(客户端)调用php(服务端)出现417错误

linux + apache(lighttpd) + php5

windowsxp + ...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/liehuo123">liehuo123</a>

2011年08月10日 11:11

2982

调用时出现...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/sweeee">sweeee</a>

2015年07月01日 11:38

3544

');

(window.slotbydup=window.slotbydup || []).push({

id: '4765209',

container: s,

size: '808,120',

display: 'inlay-fix'

});

})();

原文:http://www.cnblogs.com/zxjyuan/archive/2011/03/14/1983363.html

今天做了个文件上传,可上传文件一大,就会出现请求已超时的错误,...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/u013908405">u013908405</a>

2016年09月03日 15:50

1427

我用下面这段话:如下代码,模拟post请求,我的操作过程是先调用一次SendDataByPost获取需要的信息之后,再调用一次SendDataByPost继续下一步操作,结果提示如下异常:请教高手这是...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/youaregoo">youaregoo</a>

2013年07月16日 21:08

7202

今天调试程序,突然WebService就不能用了,提示:“System.Net.WebException: 请求因 HTTP 状态 401 失败:Unauthorized。”,找了半天没找到原因。最后...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/zjlovety">zjlovety</a>

2011年08月19日 10:01

3930

id: '4983339',

在.net中发送 xml post请求和接受xml 的post请求时,经常会遇到“远程服务器返回错误: (500) 内部服务器错误”。

这里有2种解决办法:  

第一种方法:修...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/xb12369">xb12369</a>

2012年12月12日 16:33

53872

有两张表t1、t2

t1表结构为

id、name、age

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/yangchen8497">yangchen8497</a>

2014年04月24日 13:07

437

2015年05月11日 11:37

2KB

<a href="http://download.csdn.net/detail/synull/8685711" target="_blank">下载</a>

1-数据库服务器无法连接问题凡是出现以上问题时,使用如下方法。1检查SQLServer服务是否打开:2检查连接字符串中的Server对应的服务器名称是否正确(注意默认实例,命名实例的名称)3如果示连接...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/qq_36482772">qq_36482772</a>

2017年05月02日 05:57

438

using System;

namespace chuankou

///

/// Class1 的摘要说明。

class send

/// 应用程序的主...

C# post数据时 出现如下错误: System.Net.WebException: 操作超时

<a href="http://blog.csdn.net/xinyuan178">xinyuan178</a>

2011年08月27日 14:37

6384