MSXML2.ServerXMLHTTP works only with text files?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lopi

    MSXML2.ServerXMLHTTP works only with text files?

    Hello.
    I'm trying to remotely get a pdf file - http://remoteServer/file.pdf -
    in order to store it into another server, maybe with
    Scripting.FileS ystemObject
    However the following code doesn't work properly:
    ------------
    url = "http://remoteServer/file.pdf"
    set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
    xmlhttp.open "GET", url, false
    xmlhttp.send ""
    ------------
    as xmlhttp.respons eText does not contain the whole file textStream,
    but only a part of it.
    Anyone can help?
    TIA

  • Bob Barrows [MVP]

    #2
    Re: MSXML2.ServerXM LHTTP works only with text files?

    lopi wrote:
    Hello.
    I'm trying to remotely get a pdf file - http://remoteServer/file.pdf -
    in order to store it into another server, maybe with
    Scripting.FileS ystemObject
    However the following code doesn't work properly:
    ------------
    url = "http://remoteServer/file.pdf"
    set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
    xmlhttp.open "GET", url, false
    xmlhttp.send ""
    ------------
    as xmlhttp.respons eText does not contain the whole file textStream,
    but only a part of it.
    Anyone can help?
    TIA
    There are three properties that can be used to get the output from xmlhttp:
    ResponseText
    ResponseXML
    ResponseStream

    It seems to me you need to use the last one. You should probably use an ADO
    Stream object to save it to disk.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Comment

    • lopi

      #3
      Re: MSXML2.ServerXM LHTTP works only with text files?

      On 16 Feb, 12:23, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
      wrote:
      It seems to me you need to use the last one. You should probably use an ADO
      Stream object to save it to disk.
      thanks Bob ...
      actually i have changed the code in the meanwhile
      ------------
      url = "http://remoteServer/file.pdf"
      set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
      xmlhttp.open "GET", url, false
      xmlhttp.send ""
      Response.Buffer = TRUE
      Response.Conten tType = "applicatio n/pdf"
      response.Binary Write xmlhttp.respons estream
      ------------
      but again the browser displays only a part of the pdf file, not as PDF
      obviously, but as a sequence of chars (%PDF-1.4 %ÿÿÿÿ 6 0 obj <>
      endobj xref 6 13 0000000016 00000 n 0000000719 00000 n 0000000795
      00000 n 0000000928 00000 n 0000001048 00000 n 0000002524 00000 n
      0000002558 00000 n 0000002777 00000 n 0000002971 00000 n 0000005640
      00000 n 0000005867 00000 n 0000006088 00000 n 0000000556 00000 n
      trailer <<150F4F63E5FC2 F48B1DDB1CB3371 93D0>]>startxref 0 %%EOF 18 0
      obj<>stream xÿÿ``ÿÿ`ÿÿ`)

      Comment

      • Anthony Jones

        #4
        Re: MSXML2.ServerXM LHTTP works only with text files?

        >>>>>>>>>>>>> >>
        "lopi" <lopi@iteam5.ne twrote in message
        news:1171626982 .638269.35630@j 27g2000cwj.goog legroups.com...
        On 16 Feb, 12:23, "Bob Barrows [MVP]" <reb01...@NOyah oo.SPAMcom>
        wrote:
        It seems to me you need to use the last one. You should probably use an
        ADO
        Stream object to save it to disk.
        thanks Bob ...
        actually i have changed the code in the meanwhile
        ------------
        url = "http://remoteServer/file.pdf"
        set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
        xmlhttp.open "GET", url, false
        xmlhttp.send ""
        Response.Buffer = TRUE
        Response.Conten tType = "applicatio n/pdf"
        response.Binary Write xmlhttp.respons estream
        ------------
        but again the browser displays only a part of the pdf file, not as PDF
        obviously, but as a sequence of chars (%PDF-1.4 %ÿÿÿÿ 6 0 obj <>
        endobj xref 6 13 0000000016 00000 n 0000000719 00000 n 0000000795
        00000 n 0000000928 00000 n 0000001048 00000 n 0000002524 00000 n
        0000002558 00000 n 0000002777 00000 n 0000002971 00000 n 0000005640
        00000 n 0000005867 00000 n 0000006088 00000 n 0000000556 00000 n
        trailer <<150F4F63E5FC2 F48B1DDB1CB3371 93D0>]>startxref 0 %%EOF 18 0
        obj<>stream xÿÿ``ÿÿ`ÿÿ`)
        <<<<<<<<<<<<<<< <

        I'm surprised you get even that. I wouldn't have thought ResponseStream
        would be an acceptable value to pass to BinaryWrite. You should use
        ResponseBody.

        If you still get the same results change the last couple of lines to:-

        Response.conten type = "text/html"
        Response.Write LenB(xmlHttp.Re sponseBody)

        So you can discover the exact size of whats in it. You can therefore
        determine which stage of the transfer to concentrate further investigations.



        Comment

        • lopi

          #5
          Re: MSXML2.ServerXM LHTTP works only with text files?

          On 16 Feb, 13:23, "Anthony Jones" <A...@yadayaday ada.comwrote:
          I'm surprised you get even that. I wouldn't have thought ResponseStream
          would be an acceptable value to pass to BinaryWrite. You should use
          ResponseBody.
          Thank you very much Anthony, good guess!
          I enclose the working code, for anyone may need it.
          <%
          'Byte string to string conversion
          Function getString(byVal StringBin)
          dim intCount
          getString =""
          For intCount = 1 to LenB(StringBin)
          getString = getString & chr( AscB(MidB(Strin gBin, intCount, 1)) )
          Next
          End Function

          url = "http://remoteServer/file.pdf"
          set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
          xmlhttp.open "GET", url, false
          xmlhttp.send ""
          set fileSys = Server.CreateOb ject("Scripting .FileSystemObje ct")
          set textStream = fileSys.CreateT extFile(Server. MapPath("/localDir/
          file.pdf"), True, False)
          textStream.Writ e getString(xmlht tp.ResponseBody )
          textStream.Clos e
          Set textStream = Nothing
          Set fileSys = Nothing
          %>

          Any performance issue?

          I'll try tolearn how to POST the file by MSXML2.ServerXM LHTTP, instead
          of creating it by Scripting.FileS ystemObject, it's likely to be a
          better solution.

          ciao.lopi

          Comment

          • Anthony Jones

            #6
            Re: MSXML2.ServerXM LHTTP works only with text files?


            "lopi" <lopi@iteam5.ne twrote in message
            news:1171630594 .330025.148150@ k78g2000cwa.goo glegroups.com.. .
            On 16 Feb, 13:23, "Anthony Jones" <A...@yadayaday ada.comwrote:
            I'm surprised you get even that. I wouldn't have thought ResponseStream
            would be an acceptable value to pass to BinaryWrite. You should use
            ResponseBody.
            >
            Thank you very much Anthony, good guess!
            I enclose the working code, for anyone may need it.
            <%
            'Byte string to string conversion
            Function getString(byVal StringBin)
            dim intCount
            getString =""
            For intCount = 1 to LenB(StringBin)
            getString = getString & chr( AscB(MidB(Strin gBin, intCount, 1)) )
            Next
            End Function
            >
            url = "http://remoteServer/file.pdf"
            set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
            xmlhttp.open "GET", url, false
            xmlhttp.send ""
            set fileSys = Server.CreateOb ject("Scripting .FileSystemObje ct")
            set textStream = fileSys.CreateT extFile(Server. MapPath("/localDir/
            file.pdf"), True, False)
            textStream.Writ e getString(xmlht tp.ResponseBody )
            textStream.Clos e
            Set textStream = Nothing
            Set fileSys = Nothing
            %>
            >
            Any performance issue?
            This is easier and puts less strain on your server.

            Dim oWinHTTP
            Dim oStream

            Set oWinHTTP = CreateObject("W inHttp.WinHttpR equest.5.1")

            oWinHTTP.Open "GET", "http://remoteServer/file.pdf", False
            oWinHTTP.Send

            If oWinHTTP.Status = 200 Then
            Set oStream = CreateObject("A DODB.Stream")
            oStream.Open
            oStream.Type = 1
            oStream.Write oWinHTTP.respon seBody
            oStream.SaveToF ile Server.MapPath( "/localDir/file.pdf")
            oStream.Close
            End If



            >
            I'll try tolearn how to POST the file by MSXML2.ServerXM LHTTP, instead
            of creating it by Scripting.FileS ystemObject, it's likely to be a
            better solution.
            I'm not sure what you mean?



            Comment

            • lopi

              #7
              Re: MSXML2.ServerXM LHTTP works only with text files?

              On 16 Feb, 14:17, "Anthony Jones" <A...@yadayaday ada.comwrote:
              I'm not sure what you mean?
              Something like
              -------------------
              url = "http://remoteServer/file.pdf"
              set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
              xmlhttp.open "GET", url, false
              xmlhttp.send ""
              ResponseBody = xmlhttp.Respons eBody
              If xmlhttp.Status = 200 Then
              url ="http://localServer/localDir/file.pdf"
              xmlhttp.open "POST", url, false
              xmlhttp.send ResponseBody
              End if
              Response.Write xmlhttp.Status
              -------------------
              but I obtain a status=404

              anyway, i'm easy with your solution, but what if I have to download a
              word file (.doc) instead of PDF?
              I guess there's an equivalent to CreateObject("A DODB.Stream"), where
              can I find the classes corresponding to main MIME types?

              Comment

              • Anthony Jones

                #8
                Re: MSXML2.ServerXM LHTTP works only with text files?


                "lopi" <lopi@iteam5.ne twrote in message
                news:1171634454 .572437.11580@p 10g2000cwp.goog legroups.com...
                On 16 Feb, 14:17, "Anthony Jones" <A...@yadayaday ada.comwrote:
                I'm not sure what you mean?
                >
                Something like
                -------------------
                url = "http://remoteServer/file.pdf"
                set xmlhttp = CreateObject("M SXML2.ServerXML HTTP")
                xmlhttp.open "GET", url, false
                xmlhttp.send ""
                ResponseBody = xmlhttp.Respons eBody
                If xmlhttp.Status = 200 Then
                url ="http://localServer/localDir/file.pdf"
                xmlhttp.open "POST", url, false
                xmlhttp.send ResponseBody
                End if
                Response.Write xmlhttp.Status
                -------------------
                but I obtain a status=404
                >
                anyway, i'm easy with your solution, but what if I have to download a
                word file (.doc) instead of PDF?
                I guess there's an equivalent to CreateObject("A DODB.Stream"), where
                can I find the classes corresponding to main MIME types?
                >
                The goal posts keep moving.

                Am I to believe there are now three servers involved. The server you are
                pulling from, a server where this code is running AND a different local
                server where you want to place the file??

                The code I posted will work for any type of file including Word documents.



                Comment

                • lopi

                  #9
                  Re: MSXML2.ServerXM LHTTP works only with text files?

                  On 16 Feb, 15:21, "Anthony Jones" <A...@yadayaday ada.comwrote:
                  The goal posts keep moving.
                  >
                  Am I to believe there are now three servers involved. The server you are
                  pulling from, a server where this code is running AND a different local
                  server where you want to place the file??
                  >
                  The code I posted will work for any type of file including Word documents.-
                  You're right, forget it! I was confusing myself.
                  I tried your code over a word document and it works perfectly.
                  Thank you again.

                  ciao.lopi

                  Comment

                  Working...