HTTP post problem

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have come up with 2 procedures for posting/receiving data via an http post. One posts with parameters on the url the other as form data.
I have an https url that accepts a single parameter that is xml, and the response is also xml.
in the browser it works fine, and I even have some vb6 code that works as well.
neither of the vb.net post routines below work however, I always get an underlying error has occurred, connection closed.
I have modified each routine to do GET and POST, I have sent as clear test and urlencoded the xml parameter
<span style="font-size:small <span style="font-size:small
<span>

<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small myRequest
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small System.Net.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small WebRequest<span style="font-size:small <span style="font-size:small
= Net.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small WebRequest<span style="font-size:small <span style="font-size:small .Create(url)<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small
myRequest.Method =

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "GET"<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small post parameters<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small encoding
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small New<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ASCIIEncoding<span style="font-size:small <span style="font-size:small ()<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small data()
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Byte<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small
data = encoding.GetBytes(parameters)


<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small prepare to send the data<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="font-size:small <span style="font-size:small
myRequest.ContentType =

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "application/x-www-form-urlencoded"<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="font-size:small <span style="font-size:small
myRequest.ContentLength = data.Length


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small newStream
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Stream<span style="font-size:small <span style="font-size:small = myRequest.GetRequestStream()<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small
newStream.Write(data, 0, data.Length)
newStream.Close()


<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small read the response and send it back<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small webResponse
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small System.Net.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small WebResponse<span style="font-size:small <span style="font-size:small
= myRequest.GetResponse()<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small enc
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Encoding<span style="font-size:small <span style="font-size:small = System.Text.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Encoding<span style="font-size:small <span style="font-size:small .GetEncoding(1252)<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small readStream
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="font-size:small <span style="font-size:small =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small New<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="font-size:small <span style="font-size:small (webResponse.GetResponseStream(),
enc)<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small show the response<span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="color:#008000; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Return<span style="font-size:small <span style="font-size:small readStream.ReadToEnd()<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small End<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Function<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Private<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Function<span style="font-size:small <span style="font-size:small HttpPostAsUrlEncodedData(url
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small String<span style="font-size:small <span style="font-size:small , Parameters
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small String<span style="font-size:small <span style="font-size:small )
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small String<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small reader
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small request
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small System.Net.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small HttpWebRequest<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small response
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small System.Net.<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small HttpWebResponse<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Dim<span style="font-size:small <span style="font-size:small data
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small String<span style="font-size:small <span style="font-size:small =
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small ""<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Try<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small
request = System.Net.

<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small HttpWebRequest<span style="font-size:small <span style="font-size:small .Create(url & Parameters)<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small
request.Method =

<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "GET"<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="font-size:small <span style="font-size:small
request.Timeout = 30000
response = request.GetResponse()
reader =

<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small New<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small StreamReader<span style="font-size:small <span style="font-size:small (response.GetResponseStream())<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small
data = reader.ReadToEnd()


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Catch<span style="font-size:small <span style="font-size:small ex
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small As<span style="font-size:small <span style="font-size:small
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Exception<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="font-size:small <span style="font-size:small
MsgBox(ex.Message)


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small End<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Try<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Return<span style="font-size:small <span style="font-size:small data<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small End<span style="font-size:small <span style="font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small Function<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="font-size:small <span style="font-size:small


























































View the full article
 
Back
Top