Results 1 to 16 of 16

Thread: [02/03] Retrieve An XML File From HTTP POST

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    [02/03] Retrieve An XML File From HTTP POST

    Hi,
    I have an .aspx page that I use to collect data from another company. They send the data by calling the page with a HTTP GET and listing the datain a querystring. I pick up the values using the request.querystring method and all is fine. I want to change to another company who offer the data via posting an XML file to my page. How do I go about catching the information?

    Any help much appreciated.

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03] Retrieve An XML File From HTTP POST

    seem this is what you are looking for

    http://www.xml.com/pub/a/2005/02/09/...p-request.html

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    Hi,
    Yes, I think that's what I want to do but I was hoping to do this in VB.Net rather than Javascript (I'm clueless on that!).

  4. #4
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [02/03] Retrieve An XML File From HTTP POST

    may be user can upload the xml file using htmlFile upload control and at server side u can use xml classes to parse the data from it

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    I have no control over the way the file is sent: they don't allow a choice. Is there any way to parse the file from the HTTP Post (using VB.Net)?

  6. #6
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: [02/03] Retrieve An XML File From HTTP POST

    One would assume that they've keyed the POST, in which case you should be able to use Request.Form[key] - for Java, but gives the basics: http://developers.sun.com/mobility/midp/ttips/HTTPPost/. Also worth reading: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html.

    Keep in mind that the files are not sent via HTTP; (binary) streams are. In this case, you need only extract the content from the request & create the appropriate file to store the content.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    A few things you want to look at are Request.BinaryRead, Posting Acceptor and sharing the solution with us when you're done.

    Once you get the actual binary data, the rest is easy. You can create a file out of it using FileStream, (I assume you want to save the XML file somewhere for your own records), and then load it into an XmlDocument object. You can then read the nodes from it, but you should really figure out how to handle the upload part first.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    Thanks guys, I've a few things to try now, I'll show you the solution when (if!!) it works.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    Quote Originally Posted by dec_obrien
    Thanks guys, I've a few things to try now, I'll show you the solution when (if!!) it works.
    I'm interested to have a look at it as well, when and if you finish it.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    At last, this is what I have. I think it works (the XML part definitely works). I could do with a code snippit to post a file from another aspx page to this one to test it fully though!!

    Code:
        Dim _XmlDoc As New XmlDocument()
        Dim f_Files As HttpFileCollection
        Dim iFileCount As Int32
        Dim f_PostedFile As HttpPostedFile
        Dim xOriginator As String = String.Empty
        Dim xMessage As String = String.Empty
    
        f_Files = Request.Files
    
        Dim xpathDoc As XPathDocument
        Dim xmlNav As XPathNavigator
        Dim xmlNI As XPathNodeIterator
    
        For iFileCount = 0 To f_Files.Count - 1
    
          f_PostedFile = f_Files(iFileCount)
    
          xpathDoc = New XPathDocument(f_PostedFile.InputStream)
          'xpathDoc = New XPathDocument(f_PostedFile.InputStream)
    
          'Retrieve the record
          xmlNav = xpathDoc.CreateNavigator()
          xmlNI = xmlNav.Select("info")
          xOriginator = xmlNI.Current.Value
          xmlNav = xpathDoc.CreateNavigator
          xmlNav.MoveToRoot()
    
          'Pick Up Originator
          xmlNI = xmlNav.SelectDescendants("originator", String.Empty, False)
          xmlNI.MoveNext()
          xOriginator = xmlNI.Current.Value
    
          'Pick Up Message
          xmlNI = xmlNav.SelectDescendants("message", String.Empty, False)
          xmlNI.MoveNext()
          xMessage = xmlNI.Current.Value
        Next
    This is the XML file
    HTML Code:
    <?xml version='1.0'?> 
    <info> 
    <originator>testOriginator</originator> 
    <recipient>XXXXX</recipient> 
    <date>XXXXX</date> 
    <message>This is a Test Message</message> 
    </info>

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    Request.Files, that was it!!

    I knew there was something I was forgetting, but this was from long ago. Anyways, to test your code, you will need to set the enctype in your <form> tag.

    Code:
    <form method="post" enctype="multipart/form-data" 
    
    action="http://example.com/yourfile.aspx">
    <input type="file" name="file1" id="file1" />
    <br/>
    <input type="file" name="file2" id="file2" />
    <br/>
    <input type="submit" value="Go" id="Go" name="Go" />
    </form>
    Without it, Request.Files won't work. I suppose it'd be worth having a word with them to ensure that the encoding type is indeed multipart/form-data.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    Hi, I don't fully understand!! (it's 11pm on Friday night!!!)
    If I use <form method="post" enctype="multipart/form-data" action="http://example.com/yourfile.aspx"> on Page1 (sender page), do I need to include the enctype="multipart/form-data" on Page2 (catcher page) as well? I tried something very similar to this last night but it didn't seem to call Page2. I know that there were some pedantics about removing the runat=server attribute from the form tag etc.
    Sorry for the extra questions, but as they say over here "fair exchange is no robbery" (taking credit for the request.files!!)

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    No, you only need to mention this in the <form> tag on the first page. Put the code I gave you in one page (and change the action to point to your page), then try uploading your XML files.

    If you're doing this from an ASP.NET page, then make sure you have the action in there as well, and a normal Submit button. In fact, you can take what I gave you in my post above and put that into a .html file, you don't even need to make it an ASP.NET page.

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    I just tested it out and it works fine with your code, I'm able to see two files in Request.Files.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    169

    Re: [02/03] Retrieve An XML File From HTTP POST

    I don't know what I did differently last night but now it works perfectly.

    Thanks very much for the help. It's much appreciated.

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Retrieve An XML File From HTTP POST

    Perhaps the euphoria induced adrenalin impaired your vision and you were typing <forum> instead of <form>.

    Either way, that's pretty good, I quite like it. I'm going to rate you for it and thanks for reminding me of Request.Files.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width