By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,869 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,869 IT Pros & Developers. It's quick & easy.

Problems with System.Net.WebClient

P: n/a
Hi all,

I have the following code which uses WebClient.UploadValues

myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Age", age)
Dim web As New System.Net.WebClient
web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Dim Results As Byte() =
Response.Write("Response received : " +

When the code executes, I'm getting the following error. Is this
something to do with permission problem? I've tried using form post
method(see the code at the end) and it works fine. Any idea?

Exception Details: System.Net.WebException: The underlying connection
was closed: Unable to connect to the remote server.

Source Error:

Line 244: Dim web As New System.Net.WebClient
Line 245: web.Headers.Add("Content-Type",
Line 246: Dim Results As Byte() =
myNameValueCollection )
Line 247: Response.Write("Response received : " +

Source File: c:\inetpub\wwwroot\LNAT\Secure\PaymentDetails.aspx .vb
Line: 246

Stack Trace:

[WebException: The underlying connection was closed: Unable to connect
to the remote server.]
System.Net.HttpWebRequest.CheckFinalStatus() +674
System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult) +75
System.Net.HttpWebRequest.GetRequestStream() +132
System.Net.WebClient.UploadValues(String address, String method,
NameValueCollection data)
System.Net.WebClient.UploadValues(String address,
NameValueCollection data)
EIE.Web.UI.LNAT.PaymentDetails.btnSubmit_Click(Obj ect sender,
ImageClickEventArgs e) in
c:\inetpub\wwwroot\LNAT\Secure\PaymentDetails.aspx .vb:246
System.Web.UI.WebControls.ImageButton.OnClick(Imag eClickEventArgs
e) +109
System.Web.UI.WebControls.ImageButton.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain() +1277

Other method which works fine:

Dim script As New System.Text.StringBuilder
script.Append("<form name=Form1 action=''
script.Append("<input type=hidden name='Name' value='" & UserName &
script.Append("<input type=hidden name='Age' value='" & UserAge &

Many thanks.
Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.