Reputation: 35
Why does this not works -
"The underlying connection was closed: The connection was closed unexpectedly"
static void Main()
{
using (var client = new WebClient())
{
try
{
Console.WriteLine(client.DownloadString("http://oz.by/books/more10176026.html"));
}
catch (Exception e)
{
throw;
}
}
}
Usual GET requests are OK. check it here
Upvotes: 2
Views: 1258
Reputation: 141588
The server seems to choke because there is no User Agent header. This fixes it:
using (var client = new WebClient())
{
try
{
//Add your user agent of choice. This is mine, just as an example.
client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11");
Console.WriteLine(client.DownloadString("http://oz.by/books/more10176026.html"));
}
catch (Exception e)
{
throw;
}
}
Upvotes: 3