i really need urgent help with this one, a vendor that we use is going to post XML data to one of my ASPX pages. There is nothing really in that ASPX page, they just requested a page where they can POST XML (I imagine, using a method like XMLHTTP or similar).
Now, I need to read the XML that is being posted to that file (hopefully in the same file), and parse through it... all the examples I have gotten so far offer me XML files that are viewable through a broswer, so the code simple does Webrequest.Create(URL)
but in this case I dont know if i can use that, as the URL is THE SAME FILE that is being posted at.... how can I do this? any help appreciated
"Never argue with an idiot; He will drag you down to his level and beat you with experience"
Kirk , I appreciate your response a lot let me tell you what i have: I am sending this XML document via an ASP file (for testing purposes... ):
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.load("C:\Inetpub\wwwroot\testWeb\testSend.xml")
xmlhttp.Open "POST", "http://localhost/testWeb/testRecieve.aspx", False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send xmlDoc
Set xmlhttp = Nothing
%>
now I am recieving with the ASPX file like:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim reader As New XmlTextReader(Request.InputStream)
While reader.Read
'nothing here, just a debug stop in the previous line
End While
End Sub
as you see, i am trying to use your example, without any XML processing. I stop the debugger in the loop and
the I just add a watch to the reader object... but what I see doesnt seem to be right, the reader loops only 3 times, and the xml file has lots of lines (like 300) .. shouldnt it be looping that much? it looks like the XML file is not being sent correctly....
or the problem is when i recieve it? aahhgg ,, i with i could see a simplified example of both sides, but i haven't been able to find a good one on the net
"Never argue with an idiot; He will drag you down to his level and beat you with experience"
There are a couple good troubleshooting tools you can use for this. One is tcpTrace, available at PocketSoap.com. This tool lets you see the data posted to your web server. This would be useful to see the entire request body to see if additional data is in
the post that you are not accounting for. Another tool to try is simply saving the Request. You can use Request.Save, providing a file name to save the data to. This will let you see if the data is really sent from the ASP page like you think it is. It may
be the case that the data is not being sent like you think it is. Something else to check: if the POST from the ASP page is really just XML, then you might try changing the contenttype header to "text/xml". Finally, the XmlReader might only be looping 3 times
because the XML only contains 1 element with a lot of attributes and text content. The line length itself does not matter, the number of elements is significant. Are you sure you are not getting an exception during the parsing? If the XmlReader cannot parse
the XML, it should throw an exception.
I can see the request object while I debug, but .. what property should I look at? This vendor just tells me they are using the HTTP POST... so that means that Reading the Request.InputStrem is enough? So this is not like an HTML POST where there I have to
request an item in the request collection, like Request.Form(0)? ... Now I am testing this code, to try and get it working in any possible way:
Dim req As WebRequest = WebRequest.Create("http://localhost/Web/resident.xml")
'Dim req As WebRequest = WebRequest.Create("http://p.moreover.com/cgi-local/page?c=XML%20and%20metadata%20news&o=xml")
Dim resp As WebResponse = req.GetResponse
Dim reader As New XmlTextReader(resp.GetResponseStream)
Dim doc As New XmlDocument
doc.Load(reader)
the first two declarations are trying to request an xml file, and both are valid xml files (from what I can see).. the second one is on the internet actually; when i use this seconde one the doc object gets populated with XML, but when I use the first one the debugger in VS.NET doesnt even stop, just displays a blank browser and the doc object doesnt populate anything... it doesnt even error out.... ;(
"Never argue with an idiot; He will drag you down to his level and beat you with experience"
javiguillen
Contributor
2432 Points
526 Posts
XML being posted to my ASPX
Aug 18, 2003 01:36 PM|LINK
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XML being posted to my ASPX
Aug 18, 2003 04:30 PM|LINK
XmlTextReader reader = new XmlTextReader(Request.InputStream); while(reader.Read()) { //Process the XML here } reader.Close();You can also do the same with an XmlDocument:javiguillen
Contributor
2432 Points
526 Posts
Re: XML being posted to my ASPX
Aug 18, 2003 05:08 PM|LINK
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") Set xmlDOC =CreateObject("MSXML.DOMDocument") xmlDOC.load("C:\Inetpub\wwwroot\testWeb\testSend.xml") xmlhttp.Open "POST", "http://localhost/testWeb/testRecieve.aspx", False xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xmlhttp.send xmlDoc Set xmlhttp = Nothing %>now I am recieving with the ASPX file like:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim reader As New XmlTextReader(Request.InputStream) While reader.Read 'nothing here, just a debug stop in the previous line End While End Subas you see, i am trying to use your example, without any XML processing. I stop the debugger in the loop and the I just add a watch to the reader object... but what I see doesnt seem to be right, the reader loops only 3 times, and the xml file has lots of lines (like 300) .. shouldnt it be looping that much? it looks like the XML file is not being sent correctly.... or the problem is when i recieve it? aahhgg ,, i with i could see a simplified example of both sides, but i haven't been able to find a good one on the netkaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XML being posted to my ASPX
Aug 18, 2003 07:47 PM|LINK
javiguillen
Contributor
2432 Points
526 Posts
Re: XML being posted to my ASPX
Aug 18, 2003 08:28 PM|LINK
Dim req As WebRequest = WebRequest.Create("http://localhost/Web/resident.xml") 'Dim req As WebRequest = WebRequest.Create("http://p.moreover.com/cgi-local/page?c=XML%20and%20metadata%20news&o=xml") Dim resp As WebResponse = req.GetResponse Dim reader As New XmlTextReader(resp.GetResponseStream) Dim doc As New XmlDocument doc.Load(reader) the first two declarations are trying to request an xml file, and both are valid xml files (from what I can see).. the second one is on the internet actually; when i use this seconde one the doc object gets populated with XML, but when I use the first one the debugger in VS.NET doesnt even stop, just displays a blank browser and the doc object doesnt populate anything... it doesnt even error out.... ;(