How to Read XML from HTTP Post in ASP.NET

Hey Experts,

A third party developer is going to post an xml document via HTTP to my url / asp application. I am not sure how to retrieve it and read the xml data when it is posted.

Is there a quick and easy way to do this?
Who is Participating?
rmartesAuthor Commented:
Thanks plusone, I used the code project example, but now im getting a "badrequest" @ this line: rsp = req.GetResponse()

Here is the code I'm using:

Private Sub Page_Load()
		Dim req As WebRequest = Nothing
		Dim rsp As WebResponse = Nothing
			Dim fileName As String = Server.MapPath("xml\webform.xml")
			Dim uri As String = "http://localhost:500/xml_receiver.aspx"
			req = WebRequest.Create(uri)
			'req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
			req.Method = "POST"
			' Post method
			req.ContentType = "text/xml"
			' content type
			' Wrap the request stream with a text-based writer
			Dim writer As New StreamWriter(req.GetRequestStream())
			' Write the XML text into the stream
			' Send the data to the webserver
			rsp = req.GetResponse()
		'Catch webEx As WebException
		'Catch ex As Exception
			'If req IsNot Nothing Then
			'End If
			'If rsp IsNot Nothing Then
			'End If
		'End Try

	End Sub
	Private Function GetTextFromXMLFile(file As String) As String
		Dim reader As New StreamReader(file)
		Dim ret As String = reader.ReadToEnd()
		Return ret
	End Function

Open in new window

Any clue why?
rmartesAuthor Commented:
Never mind the above. I got the post to work. I am having trouble reading the xml now. The page i setup to read the xml is stalling.

I used this code

Page.Response.ContentType = "text/xml"
			'Read XML posted via HTTP
			Dim reader As StreamReader = new StreamReader(Page.Request.InputStream)
		 	Dim xmlData As String = reader.ReadToEnd()

Open in new window

rmartesAuthor Commented:
GOT IT!!!! Thanks
rmartesAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.