Парсинг Html: Часто вылетает ошибка "Сервер нарушил протокол. Section=ResponseStatusLine" - C#
Формулировка задачи:
Часто вылетает ошибка "Сервер нарушил протокол. Section=ResponseStatusLine" , документации по ней нету, а ошибки что появлялись у других были из за прокси и забитого 80 порта.
В моем случае думаю сервер отказывается отвечать на запросы, как поступить? Воткнуть прокси на каждый второй запрос или поставить ожидание?
Так-же вылетает "Базовое соединение закрыто: Соединение было неожиданно закрыто."
Обе ошибки на первой строке.
Stream dataWeb = client.OpenRead(ссылка);//инициируем сбор хтмла по ссылке)) StreamReader reader3 = new StreamReader(dataWeb);//читалка дочитывает и сохраняет в себе string T = reader3.ReadToEnd();//переменная со всем этим говном
Решение задачи: «Парсинг Html: Часто вылетает ошибка "Сервер нарушил протокол. Section=ResponseStatusLine"»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using HtmlAgilityPack;
using System.Web;
namespace proba
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
Stream data = client.OpenRead("http://softlab-portable.ru/index.php?newsid=186001");
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(s);
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//*[@id='news-id-186001']");
if (nodes != null)
{
foreach (var tag in nodes)
{
if (tag.Attributes["div"] != null)
{
textBox1.Text = tag.Attributes["div"].Value;
}
}
}
}
}
}