473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problems with System.Net.WebClient

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(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)
+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
Nov 18 '05 #1
0 4031

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred...
3
by: Bruno Otero | last post by:
Hi! I have a program that excutes the following code: DirectoryInfo diretorio = new DirectoryInfo(@"C:\teste"); FileInfo arquivos = diretorio.GetFiles("*.xml"); for(int...
2
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
0
by: David W | last post by:
I am trying to upload a file from a user's system to my web server. I found code using the WebClient.UploadFile method. However, the uploaded file is from the server's hard drive not the user's...
2
by: Jerry Spence1 | last post by:
I am trying to get a jpg image as follows: Dim Client As System.Net.WebClient = New System.Net.WebClient Client.DownloadFile("http://root:<password>@192.168.0.99/cgi-bin/video.jpg", MyFilename)...
3
by: df | last post by:
Hi, I'm trying to download the web page source code from a HTTPS URL, my code is as follows: Code: System.Net.WebClient WC = new System.Net.WebClient(); NetworkCredential Cred = new...
3
by: Giggi | last post by:
Hi! I need to pass some strings via an HTTP POST from page1 (in my app) to a page on another server. I stored my data in a NameValueCollection and then sent it using WebClient.UploadValues....
1
by: Mike | last post by:
I am using PowerShell to download an XML file into a string using the DownloadString(URI) method of System.Net.WebClient object. Sample commands below: $Result = $Null; $WebClient = new-object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.