Forum Moderators: open

Message Too Old, No Replies

.NET Programmattic Form Post

Need to send XML doc in form post (vb.Net)

         

AlphaChimp

3:33 am on Sep 7, 2005 (gmt 0)

10+ Year Member



I need to send an XML doc in a form post programmatically . I need to create the form content including header information, post it to a remote server, and read the response from the remote server.

I would really benefit from a concise sample (in vb.NET) demonstrating how I might accomplish this task.

--Deadlines take the fun out of learning

tomasz

5:43 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



Try this function, it should work just pass xml as string

Protected Function UploadValues(ByVal xml As String) As String
Dim myWebClient As New WebClient
Dim URL As String = "put post url here"
Dim myNameValueCollection As New System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("xml", xml)
Try
Dim responseArray As Byte() = myWebClient.UploadValues(URL, "POST", myNameValueCollection)
UploadValues = Encoding.ASCII.GetString(responseArray)
'here is you stream from source
Catch ex As Exception
Return ex.Message
End Try
End Function

AlphaChimp

9:48 pm on Sep 12, 2005 (gmt 0)

10+ Year Member



Thanks, tomasz. I am missing something key here because I cannot see a response. Where in your sample is the "POST" sent to the server?

tomasz

12:38 am on Sep 13, 2005 (gmt 0)

10+ Year Member



Protected Function UploadValues(ByVal xml As String) As String
Dim myWebClient As New WebClient
Dim URL As String = "put post url here"
Dim myNameValueCollection As New System.Collections.Specialized.NameValueCollection
myNameValueCollection.Add("xml", xml)
Try
Dim responseArray As Byte() = myWebClient.UploadValues(URL, "POST", myNameValueCollection)
UploadValues = Encoding.ASCII.GetString(responseArray)
'here is you stream from source
Catch ex As Exception
Return ex.Message
End Try
End Function

you response is UploadValues

lblPostXMLResult.Text=UploadValues(myXMLstring)
<snip>

[edited by: Xoc at 12:16 am (utc) on Oct. 27, 2005]