Posting and Receiving XML Data in VB.NET
Can any one pls help and take a look at this code/ I'm trying to Post to a page and at the other end receive the xml Data but am getting '500 internal server error'
here is the code part for POSTing
Dim objRequest As HttpWebRequest = WebRequest.Create(TextBox2.Text)
Dim formData As String = "myField=" & System.Web.HttpUtility.UrlEncode(TextBox1.Text)
objRequest.ContentLength = formData.Length
'objRequest.ContentLength = TextBox1.Text.Length
objRequest.ContentType = "text/xml"
objRequest.Method = "POST"
Dim stmWriter As New System.IO.StreamWriter(objRequest.GetRequestStream ())
stmWriter.Write(formData)
stmWriter.Close()
Try
Dim objResponse As System.Net.HttpWebResponse = objRequest.GetResponse()
Dim stmReader As New System.IO.StreamReader(objResponse.GetResponseStre am())
Dim stringResult As String = stmReader.ReadToEnd()
stmReader.Close()
Catch ex As Exception
Response.Write(ex.Message)
End Try
this is the one receiving
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Response.ContentType = "text/xml"
Dim xmlStream As New System.IO.StreamReader(Page.Request.InputStream)
Dim xmlData As String = xmlStream.ReadToEnd
....
processing codes for the data
...
Any comments or advice will be highly appreciated.
|