469,898 Members | 1,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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.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

Feb 16 '07 #1
8 20496
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"
Feb 16 '07 #2
On 16 Feb, 12:23, "Bob Barrows [MVP]" <reb01...@NOyahoo.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("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˙˙``˙˙`˙˙`)

Feb 16 '07 #3
>>>>>>>>>>>>>>>
"lopi" <lo**@iteam5.netwrote in message
news:11*********************@j27g2000cwj.googlegro ups.com...
On 16 Feb, 12:23, "Bob Barrows [MVP]" <reb01...@NOyahoo.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("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.

Feb 16 '07 #4
On 16 Feb, 13:23, "Anthony Jones" <A...@yadayadayada.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(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

Feb 16 '07 #5

"lopi" <lo**@iteam5.netwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
On 16 Feb, 13:23, "Anthony Jones" <A...@yadayadayada.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(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?

Feb 16 '07 #6
On 16 Feb, 14:17, "Anthony Jones" <A...@yadayadayada.comwrote:
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?

Feb 16 '07 #7

"lopi" <lo**@iteam5.netwrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
On 16 Feb, 14:17, "Anthony Jones" <A...@yadayadayada.comwrote:
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.

Feb 16 '07 #8
On 16 Feb, 15:21, "Anthony Jones" <A...@yadayadayada.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

Feb 16 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by André Rosendaal | last post: by
50 posts views Thread by Michael Mair | last post: by
4 posts views Thread by knapak | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.