C
CindyH
Hi
Trying to get this code to work for http xml post.
I need the post to be xml (doc.outerxml) sent in single key name as stream.
The following is the post code and code for receiving the request.
When it hits the "myresponse = myrequest.GetResponse()" in the post code -
I'm getting following error:
"The remote server returned an error: (500) Internal Server Error".
I don't know if I have something wrong with the post or receiving it on the
other end.
Right now I'm trying to write it in .net 1.1.
Any help will be greatly appreciated.
Thanks,
Cindy
Dim url As String = "http://someplace.aspx"
Dim myrequest As System.Net.WebRequest = Nothing
Dim myresponse As System.Net.WebResponse = Nothing
Try
' Create a request using a URL that can receive a post.
myrequest = System.Net.WebRequest.Create(url)
' Set the Method property of the request to POST.
myrequest.Method = "POST"
' Set the ContentType property of the WebRequest.
myrequest.ContentType = "application/x-www-form-urlencoded"
' Create POST data and convert it to a byte array.
Dim vxml = "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
' Set the ContentLength property of the WebRequest.
myrequest.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As System.io.Stream =
myrequest.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
myresponse = myrequest.GetResponse() 'error occurs here
Catch ex As Exception
Throw ex
Finally
' Closed streams
If Not myrequest Is Nothing Then
myrequest.GetRequestStream().Close()
If Not myresponse Is Nothing Then
myresponse.GetResponseStream().Close()
End Try
Code for receiving the post:
Dim strReader As System.IO.StringReader = Nothing
Dim Reader As System.Xml.XmlTextReader = Nothing
Response.ContentType = "application/x-www-form-urlencoded"
Response.Clear()
Try
strReader = New
System.IO.StringReader(Request.Form("Interface_2"))
Reader = New System.Xml.XmlTextReader(strReader)
Do While Reader.Read()
Trying to get this code to work for http xml post.
I need the post to be xml (doc.outerxml) sent in single key name as stream.
The following is the post code and code for receiving the request.
When it hits the "myresponse = myrequest.GetResponse()" in the post code -
I'm getting following error:
"The remote server returned an error: (500) Internal Server Error".
I don't know if I have something wrong with the post or receiving it on the
other end.
Right now I'm trying to write it in .net 1.1.
Any help will be greatly appreciated.
Thanks,
Cindy
Dim url As String = "http://someplace.aspx"
Dim myrequest As System.Net.WebRequest = Nothing
Dim myresponse As System.Net.WebResponse = Nothing
Try
' Create a request using a URL that can receive a post.
myrequest = System.Net.WebRequest.Create(url)
' Set the Method property of the request to POST.
myrequest.Method = "POST"
' Set the ContentType property of the WebRequest.
myrequest.ContentType = "application/x-www-form-urlencoded"
' Create POST data and convert it to a byte array.
Dim vxml = "Interface_2=" + HttpUtility.UrlEncode(Doc.OuterXml)
Dim byteArray As Byte() =
System.Text.Encoding.UTF8.GetBytes(vxml)
' Set the ContentLength property of the WebRequest.
myrequest.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As System.io.Stream =
myrequest.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
myresponse = myrequest.GetResponse() 'error occurs here
Catch ex As Exception
Throw ex
Finally
' Closed streams
If Not myrequest Is Nothing Then
myrequest.GetRequestStream().Close()
If Not myresponse Is Nothing Then
myresponse.GetResponseStream().Close()
End Try
Code for receiving the post:
Dim strReader As System.IO.StringReader = Nothing
Dim Reader As System.Xml.XmlTextReader = Nothing
Response.ContentType = "application/x-www-form-urlencoded"
Response.Clear()
Try
strReader = New
System.IO.StringReader(Request.Form("Interface_2"))
Reader = New System.Xml.XmlTextReader(strReader)
Do While Reader.Read()