MSXML2.ServerXMLHTTP works only with text files?
MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 11:42:48 von lopi
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.FileSystemObject
However the following code doesn't work properly:
------------
url = "http://remoteServer/file.pdf"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
------------
as xmlhttp.responseText does not contain the whole file textStream,
but only a part of it.
Anyone can help?
TIA
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 12:23:28 von reb01501
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.FileSystemObject
> However the following code doesn't work properly:
> ------------
> url = "http://remoteServer/file.pdf"
> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
> xmlhttp.open "GET", url, false
> xmlhttp.send ""
> ------------
> as xmlhttp.responseText 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"
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 12:56:22 von lopi
On 16 Feb, 12:23, "Bob Barrows [MVP]"
wrote:
> It seems to me you need to use the last one. You should probably use an A=
DO
> Stream object to save it to disk.
thanks Bob ...
actually i have changed the code in the meanwhile
------------
url =3D "http://remoteServer/file.pdf"
set xmlhttp =3D CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
Response.Buffer =3D TRUE
Response.ContentType =3D "application/pdf"
response.BinaryWrite xmlhttp.responsestream
------------
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 <<150F4F63E5FC2F48B1DDB1CB337193D0>]>> startxref 0 %%EOF 18 0
obj<>stream xÿÿ``ÿÿ`ÿÿ`)
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 13:23:39 von Anthony Jones
>>>>>>>>>>>>>>>
"lopi" wrote in message
news:1171626982.638269.35630@j27g2000cwj.googlegroups.com...
On 16 Feb, 12:23, "Bob Barrows [MVP]"
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("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
Response.Buffer = TRUE
Response.ContentType = "application/pdf"
response.BinaryWrite xmlhttp.responsestream
------------
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 <<150F4F63E5FC2F48B1DDB1CB337193D0>]>> 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.contentype = "text/html"
Response.Write LenB(xmlHttp.ResponseBody)
So you can discover the exact size of whats in it. You can therefore
determine which stage of the transfer to concentrate further investigations.
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 13:56:34 von lopi
On 16 Feb, 13:23, "Anthony Jones" wrote:
> 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(StringBin, intCount, 1)) )
Next
End Function
url = "http://remoteServer/file.pdf"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
set fileSys = Server.CreateObject("Scripting.FileSystemObject")
set textStream = fileSys.CreateTextFile(Server.MapPath("/localDir/
file.pdf"), True, False)
textStream.Write getString(xmlhttp.ResponseBody)
textStream.Close
Set textStream = Nothing
Set fileSys = Nothing
%>
Any performance issue?
I'll try tolearn how to POST the file by MSXML2.ServerXMLHTTP, instead
of creating it by Scripting.FileSystemObject, it's likely to be a
better solution.
ciao.lopi
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 14:17:09 von Anthony Jones
"lopi" wrote in message
news:1171630594.330025.148150@k78g2000cwa.googlegroups.com.. .
> On 16 Feb, 13:23, "Anthony Jones" wrote:
> > 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(StringBin, intCount, 1)) )
> Next
> End Function
>
> url = "http://remoteServer/file.pdf"
> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
> xmlhttp.open "GET", url, false
> xmlhttp.send ""
> set fileSys = Server.CreateObject("Scripting.FileSystemObject")
> set textStream = fileSys.CreateTextFile(Server.MapPath("/localDir/
> file.pdf"), True, False)
> textStream.Write getString(xmlhttp.ResponseBody)
> textStream.Close
> 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("WinHttp.WinHttpRequest.5.1")
oWinHTTP.Open "GET", "http://remoteServer/file.pdf", False
oWinHTTP.Send
If oWinHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oWinHTTP.responseBody
oStream.SaveToFile Server.MapPath("/localDir/file.pdf")
oStream.Close
End If
>
> I'll try tolearn how to POST the file by MSXML2.ServerXMLHTTP, instead
> of creating it by Scripting.FileSystemObject, it's likely to be a
> better solution.
I'm not sure what you mean?
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 15:01:00 von lopi
On 16 Feb, 14:17, "Anthony Jones" wrote:
> I'm not sure what you mean?
Something like
-------------------
url = "http://remoteServer/file.pdf"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
ResponseBody = xmlhttp.ResponseBody
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("ADODB.Stream"), where
can I find the classes corresponding to main MIME types?
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 15:21:59 von Anthony Jones
"lopi" wrote in message
news:1171634454.572437.11580@p10g2000cwp.googlegroups.com...
> On 16 Feb, 14:17, "Anthony Jones" wrote:
> > I'm not sure what you mean?
>
> Something like
> -------------------
> url = "http://remoteServer/file.pdf"
> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
> xmlhttp.open "GET", url, false
> xmlhttp.send ""
> ResponseBody = xmlhttp.ResponseBody
> 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("ADODB.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.
Re: MSXML2.ServerXMLHTTP works only with text files?
am 16.02.2007 15:52:29 von lopi
On 16 Feb, 15:21, "Anthony Jones" wrote:
> 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