HttpWebResponse: ошибка "WebException не обработано" - C#
Формулировка задачи:
public string get_html(string adress) // процедура получения html кода страницы
{
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(adress);
[COLOR="Red"]HttpWebResponse response = (HttpWebResponse)request.GetResponse();[/COLOR]
Stream resStream = response.GetResponseStream();
int count = 0;
string code_get = "";
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
sb.Append(Encoding.UTF8.GetString(buf, 0, count));
}
}
while (count > 0);
code_get=sb.ToString();
return code_get;
}Решение задачи: «HttpWebResponse: ошибка "WebException не обработано"»
textual
Листинг программы
using System;
using System.IO;
using xNet.Net;
using xNet.Text;
namespace temp_1
{
class Program
{
static void Main(string[] args)
{
string code = "";
try
{
using (var Request = new HttpRequest())
{
code = Request.Get("http://www.yandex.ru/").ToString();
}
}
catch { }
Console.WriteLine(code);
Console.ReadKey();
}
}
}