Problems with System.Net.WebClient

K

Kumar

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() =
web.UploadValues("https://hsbc-secure.com/cgi","POST",
myNameValueCollection)
Response.Write("Response received : " +
Encoding.ASCII.GetString(Results))

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",
"application/x-www-form-urlencoded")
Line 246: Dim Results As Byte() =
web.UploadValues("https://hsbc-secure.com/cgi","POST",
myNameValueCollection )
Line 247: Response.Write("Response received : " +
Encoding.ASCII.GetString(Results))

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(IAsyncResult
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(Object sender,
ImageClickEventArgs e) in
c:\inetpub\wwwroot\LNAT\Secure\PaymentDetails.aspx.vb:246
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs
e) +109
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1277

Other method which works fine:

Dim script As New System.Text.StringBuilder
script.Append("<form name=Form1 action='https://hsbc-secure.com/cgi'
method=POST>")
script.Append("<input type=hidden name='Name' value='" & UserName &
"'>")
script.Append("<input type=hidden name='Age' value='" & UserAge &
"'>")
script.Append("</form>")
script.Append("<script
language=javascript>cpiForm.submit();</script>")
Response.Write(script.ToString())

Many thanks.
SSK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top