views:

321

answers:

2

I'm trying to parse a URL, but I'm having problems:

http://www.meteor.gov.tr/deniz/deniz-suyu-sicakligi.aspx

When I call HttpWebRequest it throws a exception:

System.Net.Sockets.SocketException:

Eine vorhandene Verbindung wurde vom Remotehost geschlossen

In english:

System.Net.Sockets.SocketException: a existing connection was closed by the RemoteHost

I think it has do with IIS or ASP.NET. I don't have this problem with any other URL.

What can I do now?

A: 

Define "parse URL". If you just want to parse http://www.meteor.gov.tr/deniz/deniz-suyu-sicakligi.aspx string, construct a System.Uri instance with this string as a constructor argument.

If you want to download content of this page, use HttpWebRequest.

Anton Gogolev
I want to save the HTML Code into a text file for further processing (getting temperature)
+1  A: 

The remote host is probably closing the connection as something is identified as not right. Check the kind of data (HTTP headers) you are sending with your GET/POST request and try to make it similar to a web browser's (e.g. my web browser can view the page).

If you do these things, there is nothing to separate the two calls from one another, making most remote hosts believe you are a legitimate visitor.

_NT
Dim objWebClient As New WebClient() objWebClient.UseDefaultCredentials = True objWebClient.Headers.Add(HttpRequestHeader.UserAgent, "cemundo")At least it throws no exception. seems to work, thank you