小编Pro*_*nan的帖子

当我尝试获取URL的内容时应用程序冻结

首先看我的源代码:

WebClient client = new WebClient();
String url = "http://localhost";
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
try
{
    Stream data = client.OpenRead(url);
    if (data == null)
        throw new WebException("Cannot browse the url...");
    StreamReader reader = new StreamReader(data);
    string s = reader.ReadToEnd();
    textBox1.Text = s;
    data.Close();
    reader.Close();

}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}  
Run Code Online (Sandbox Code Playgroud)

当我运行我的应用程序时,它将在此操作的持续时间内冻结.
我的代码中哪一部分错了?

c# http

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

标签 统计

c# ×1

http ×1