WebException caused by Net.WebClient

  • Thread starter Thread starter Jens Kreier
  • Start date Start date
J

Jens Kreier

Hello everybody!

I got a problem with a nearly undocumented (maybe-)bug in the
WebClient class. Anyways the problem is as follows:

When I try to work with the simple WebClient.DownloadFile(URL)
function everything works fine as long as I download static
HTML-pages. As soon as I try to get the content of a remote ASP page
nothing works and I get a WebException as mentioned in the subject.

I tried the work-around with using the HttpWebResponse/Request classes
and setting HttpWebRequest.KeepAlive to "false" but it won't work.

I don't have a clue if this problem is really a problem but I tried
many independent ASP-pages but always the same problem. The problem is
that I MUST get somehow Response GET-Parameters from a ASP webpage
located at one of our partners pages, what acts as a interface to
their database. So if you got any ideas or other workarounds please
tell me. It took a lot of tears and coffee ^^

Kind Regards,
Jens Kreier
 
Jens said:
Hello everybody!

I got a problem with a nearly undocumented (maybe-)bug in the
WebClient class. Anyways the problem is as follows:

When I try to work with the simple WebClient.DownloadFile(URL)
function everything works fine as long as I download static
HTML-pages. As soon as I try to get the content of a remote ASP page
nothing works and I get a WebException as mentioned in the subject.

What WebException? Always check its Status property, and if that's
ProtocolError, also read from the eception's Response property the
actual error page returned by the remote host or proxy. That may
contain crucial information about what went wrong.

I tried the work-around with using the HttpWebResponse/Request classes
and setting HttpWebRequest.KeepAlive to "false" but it won't work.

I have no clue where this idea of turning off persistent connections
will help comes from, but unless one deals with some stoneage server,
it's not likely to work.
I don't have a clue if this problem is really a problem but I tried
many independent ASP-pages but always the same problem. The problem is
that I MUST get somehow Response GET-Parameters from a ASP webpage
located at one of our partners pages, what acts as a interface to
their database. So if you got any ideas or other workarounds please
tell me. It took a lot of tears and coffee ^^

It's still not very clear to me what you're trying to achieve (other
than a GET to a ASP page). Can you post your code and exception details
as explained above?

Cheers,
 
What WebException? Always check its Status property, and if that's
ProtocolError, also read from the eception's Response property the
actual error page returned by the remote host or proxy. That may
contain crucial information about what went wrong.



I have no clue where this idea of turning off persistent connections
will help comes from, but unless one deals with some stoneage server,
it's not likely to work.


It's still not very clear to me what you're trying to achieve (other
than a GET to a ASP page). Can you post your code and exception details
as explained above?

Cheers,

Hello Joerg!

I tried to get some informations from the WebException before. But it
simply says that the WebClient-Class couldn't establish a connection
to that specific page. The problem is that this page is reachable with
a simple web-browser. It's just not accessible through the
WebClient.DownloadData method.

Ok. The sourcecode of one of the functions:

Public Function CreateUser(ByVal firstName As String, ByVal
lastName As String, ByVal street As String, ByVal zipCode As String,
ByVal town As String, ByVal email As String, ByVal username As String,
ByVal password As String, ByVal Instance As Instance, ByVal Redirect
As String) As String

Dim Web As New WebClient

Web.Headers.Add("BoxVorname", firstName)
Web.Headers.Add("BoxNachname", lastName)
Web.Headers.Add("BoxStrasse", street)
Web.Headers.Add("BoxPLZ", zipCode)
Web.Headers.Add("BoxOrt", town)
Web.Headers.Add("BoxEMail", email)
Web.Headers.Add("BoxBenutzername", username)
Web.Headers.Add("BoxPasswort", password)
Web.Headers.Add("TestNr", "20001")
Web.Headers.Add("Credits", "0")
Web.Headers.Add("Instanz", Instance.ToString)
Web.Headers.Add("GruppenID", 20)
Web.Headers.Add("Redirect", "#")

Dim Data() As Byte =
Web.DownloadData("http://www.xxxx.xxx/iexam/formproc.asp")
Dim UserId As String = Web.ResponseHeaders("UID")

Return UserId

End Function




Alright and the output with the exception details:


System.Net.WebException: The underlying connection was closed: Unable
to connect to the remote server. at
System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse() at
System.Net.WebClient.DownloadData(String address) at
Certnet.Web.MMSI.iExamAdapter.CreateUser(String firstName, String
lastName, String street, String zipCode, String town, String email,
String username, String password, Instance Instance, String Redirect)
in C:\Inetpub\wwwroot\Certnet.Web.MMSI\Classes\iExamAdapter.vb:line 68
at Certnet.Web.MMSI.Ic3.CreateUser() in
C:\Inetpub\wwwroot\Certnet.Web.MMSI\Ic3.aspx.vb:line 93 at
Certnet.Web.MMSI.Ic3.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\Certnet.Web.MMSI\Ic3.aspx.vb:line 132


The Response-field only keeps a simple value: "ConnectFailure"


Thanks
 
Jens said:
page >> nothing works and I get a WebException as mentioned in the
subject.
classes >> and setting HttpWebRequest.KeepAlive to "false" but it
won't work.
problem is >> that I MUST get somehow Response GET-Parameters from a
ASP webpage >> located at one of our partners pages, what acts as a
interface to >> their database. So if you got any ideas or other
workarounds please >> tell me. It took a lot of tears and coffee ^^

Hello Joerg!

I tried to get some informations from the WebException before. But it
simply says that the WebClient-Class couldn't establish a connection
to that specific page. The problem is that this page is reachable with
a simple web-browser. It's just not accessible through the
WebClient.DownloadData method.

Ok. The sourcecode of one of the functions:

Public Function CreateUser(ByVal firstName As String, ByVal
lastName As String, ByVal street As String, ByVal zipCode As String,
ByVal town As String, ByVal email As String, ByVal username As String,
ByVal password As String, ByVal Instance As Instance, ByVal Redirect
As String) As String

Dim Web As New WebClient

Web.Headers.Add("BoxVorname", firstName)
Web.Headers.Add("BoxNachname", lastName)
Web.Headers.Add("BoxStrasse", street)
Web.Headers.Add("BoxPLZ", zipCode)
Web.Headers.Add("BoxOrt", town)
Web.Headers.Add("BoxEMail", email)
Web.Headers.Add("BoxBenutzername", username)
Web.Headers.Add("BoxPasswort", password)
Web.Headers.Add("TestNr", "20001")
Web.Headers.Add("Credits", "0")
Web.Headers.Add("Instanz", Instance.ToString)
Web.Headers.Add("GruppenID", 20)
Web.Headers.Add("Redirect", "#")

Ugh. You're confusing HTTP headers with form data, aren't you?

You should either put these key/vlaue pairs in your request URL as
query string, or use WebClient.UploadValues() to post this as form data.

Your request might be dying at some secure reverse proxy that
intercepts unknown HTTP headers, of which you supply plenty ;-)

Cheers,
 
Ugh. You're confusing HTTP headers with form data, aren't you?

You should either put these key/vlaue pairs in your request URL as
query string, or use WebClient.UploadValues() to post this as form data.

Your request might be dying at some secure reverse proxy that
intercepts unknown HTTP headers, of which you supply plenty ;-)

Cheers,

Hehe I thought that the headers collection might be wrong ;-)
But I also tried to use UploadValues for uploading a
NameValueCollection containing the above mentioned values, but i get
the same error. So it is possible that some proxy cancels the request
when he gets some "invalid"/unknown HTTP Headers ?

I will try it once again with .UploadValues() and if that still won't
work I need some solution to call a webpage without some 80second
delay and without the good old WebException.

Thanks anyways!
 
Ugh. You're confusing HTTP headers with form data, aren't you?

You should either put these key/vlaue pairs in your request URL as
query string, or use WebClient.UploadValues() to post this as form data.

Your request might be dying at some secure reverse proxy that
intercepts unknown HTTP headers, of which you supply plenty ;-)

Cheers,

After days of waiting my ISP finally came up with a proxy-adress to
use. And well after some work with HttpWebRequest and HttpWebResponse
it finally worked. Thanks anyways for the answers!

Cheerio,
Jens
 
Jens Kreier wrote:

[...]
After days of waiting my ISP finally came up with a proxy-adress to
use. And well after some work with HttpWebRequest and HttpWebResponse
it finally worked. Thanks anyways for the answers!

Damn those transparent proxies ;-)

Glad that it works now!
 
Back
Top