小编Aar*_*ron的帖子

C#中的不间断异常

我正在编写一些C#2.0代码,它必须执行基本的HTTP GET和POST.我正在使用System.Net.HttpWebRequest发送两种类型的请求和System.Net.HttpWebResponse来接收这两种类型.我的GET代码如下:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format("{0}?{1}",
    URLToHit,
    queryString));
request.Method = "GET";
request.Timeout = 1000; // set 1 sec. timeout
request.ProtocolVersion = HttpVersion.Version11; // use HTTP 1.1
try
{
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
catch(WebException e)
{
    // If I do anything except swallow the exception here, 
    // I end up in some sort of endless loop in which the same WebException 
    // keeps being re-thrown by the GetResponse method. The exception is always 
    // right (ie: in cases when I'm …
Run Code Online (Sandbox Code Playgroud)

c# system.net .net-2.0

5
推荐指数
1
解决办法
1055
查看次数

标签 统计

.net-2.0 ×1

c# ×1

system.net ×1