天天看點

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