473,715 Members | 4,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSXML2.ServerXM LHTTP 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

Feb 16 '07 #1
8 21790
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"
Feb 16 '07 #2
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˙˙``˙˙`˙˙`)

Feb 16 '07 #3
>>>>>>>>>>>>> >>
"lopi" <lo**@iteam5.ne twrote in message
news:11******** *************@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.

Feb 16 '07 #4
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

Feb 16 '07 #5

"lopi" <lo**@iteam5.ne twrote in message
news:11******** **************@ 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?

Feb 16 '07 #6
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?

Feb 16 '07 #7

"lopi" <lo**@iteam5.ne twrote in message
news:11******** *************@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.

Feb 16 '07 #8
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

Feb 16 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2241
by: André Rosendaal | last post by:
Hi, I need a test so I can determine whether a url points to a text file or to a binary file. Actually, I need to distinguish between streaming files and metafiles (e.g. asx files). I tried getmimetype, but that does not seem te be reliab;e (dependent on the web server configuration). Can anyone help? The test should be something like: get url if isbinaryfile ($url) {
50
4999
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem -- the character input is a different matter, at least if I want to remain within the bounds of the standard library.
4
3691
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the following code that compiles OK. It runs and shows the requested output. However, after execution, it pops one of those windows to send error reports online to the porgram creator. I have managed to find where the error is but can't see what's wrong....
2
1959
by: Darin | last post by:
I have the following code that opens a comma-delimited text file: connS = "Provider=Microsoft.Jet.OLEDB.4.0;" connS &= "Data Source=\tmp;" connS &= "Extended Properties=""text;HDR=No;FMT=Delimited""" Dim tmpConnection As New System.Data.OleDb.OleDbConnection(connS) tmpConnection.Open() strsql = "SELECT * FROM PAYROLL.TXT" Dim da As New System.Data.OleDb.OleDbDataAdapter(strsql, tmpConnection)
2
1235
by: Gaz | last post by:
> Hi all > > I am trying to write a program that opens a text file and manipulates the data. > > I have managed to open the text file into a textbox1 as a string > i now wish to add code to a button that will find a line in the string that begins with a certain letter eg I and when it does i want to insert a value eg 2 into a set character distance on the line. Can anyone help me with a loop that could do this or another way please?
5
1334
by: mojtabasah | last post by:
I want to know if there is any function in that reads a whole line from a file each time I use it. The file format is txt.
1
1434
by: chrisnova123 | last post by:
Hello, I'm a begginner with visual basic and need some help with a problem and would appreciate any help that can be offered I would like vb to read a string of text in a text file like the following example: 223-1000-23,C23,C8,C59,C35 223-0000-22,C99,C345 and output like below in new txt file
7
2138
eragon
by: eragon | last post by:
i have a script that will write to a text file from a form... using php scripts.. now i need a script to call from this file line by line, or any similar way of posting it, and insert it into my php home page. i have the script set up and working, it posts a headline on say line 1, a news article on line 2, and line 3 is blank. then when i submit again it posts a headline on line 4, a news article on line 5, and line 6 is blank. the txt file...
0
1139
by: coconet | last post by:
I have an app.config file in my Visual Studio 2008 (with TFS integration) Test Project. If I set a break point in a test method, I can see that the app.config has been read. However, the app.config points to a list.txt file that I have set as "content" and "copy when newer" - but it cannot be found. How can I make the test project respect my additional text files? I don't care what I have to do to get the path understoof, but the files...
0
8821
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.