Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using msxml2.xmlhttp to automate downloads

All,

I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.

Any suggestions?

My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.

----- code follows -----

Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request

'Wait for request to finish
Do While oXMLHTTP.readyState < 4
DoEvents
Loop

oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) < "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

'Clear memory
Set oXMLHTTP = Nothing
End Function

----- end code -----

Thanks in advance,
John Warren

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default Using msxml2.xmlhttp to automate downloads

Hmmm. For one thing, the XMLHTTP method is asynchronous when using
"False" as the third parameter, so there should be no reason to check
the ReadyState value. For example, here's a version of a subroutine I
use:

Public Function GetURLData(pURL As String) As String
On Error GoTo ErrorExit
Dim oHTTP As New XMLHTTP
oHTTP.Open "GET", pURL, False
oHTTP.Send
If oHTTP.Status = "200" Then GetURLData = oHTTP.responseText Else
GoTo ErrorExit
Exit Function
ErrorExit:
GetURLData = "Error"
End Function

I just tried it on a file that is larger than 135KB and had no problem
-- I got the full 279KB. Have you checked the length of the returned
data, or are you just getting 135KB in the output file? That is, are
you sure it's XMLHTTP that is the problem?

================ wrote:

I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.

Any suggestions?

My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.

----- code follows -----

Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request

'Wait for request to finish
Do While oXMLHTTP.readyState < 4
DoEvents
Loop

oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) < "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

'Clear memory
Set oXMLHTTP = Nothing
End Function

----- end code -----

Thanks in advance,
John Warren


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using msxml2.xmlhttp to automate downloads

On Jun 25, 10:50 pm, Randy Harmelink wrote:
Hmmm. For one thing, the XMLHTTP method is asynchronous when using
"False" as the third parameter, so there should be no reason to check
the ReadyState value. For example, here's a version of a subroutine I
use:

Public Function GetURLData(pURL As String) As String
On Error GoTo ErrorExit
Dim oHTTP As New XMLHTTP
oHTTP.Open "GET", pURL, False
oHTTP.Send
If oHTTP.Status = "200" Then GetURLData = oHTTP.responseText Else
GoTo ErrorExit
Exit Function
ErrorExit:
GetURLData = "Error"
End Function

I just tried it on a file that is larger than 135KB and had no problem
-- I got the full 279KB. Have you checked the length of the returned
data, or are you just getting 135KB in the output file? That is, are
you sure it's XMLHTTP that is the problem?

================ wrote:

I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.


Any suggestions?


My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.


----- code follows -----


Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte


Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request


'Wait for request to finish
Do While oXMLHTTP.readyState < 4
DoEvents
Loop


oResp = oXMLHTTP.responseBody 'Returns the results as a byte array


'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) < "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF


'Clear memory
Set oXMLHTTP = Nothing
End Function


----- end code -----


Thanks in advance,
John Warren

Randy,

Thanks, I tried your function on a longish file and it seems to work.
I'm at home now and need to be at work to run a better test, but I'll
try it and let you know how things work out. I'll also check the
length of the string returned by the original version.

John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using msxml2.xmlhttp to automate downloads

On Jun 27, 9:14 pm, wrote:
On Jun 25, 10:50 pm, Randy Harmelink wrote:



Hmmm. For one thing, the XMLHTTP method is asynchronous when using
"False" as the third parameter, so there should be no reason to check
the ReadyState value. For example, here's a version of a subroutine I
use:


Public Function GetURLData(pURL As String) As String
On Error GoTo ErrorExit
Dim oHTTP As New XMLHTTP
oHTTP.Open "GET", pURL, False
oHTTP.Send
If oHTTP.Status = "200" Then GetURLData = oHTTP.responseText Else
GoTo ErrorExit
Exit Function
ErrorExit:
GetURLData = "Error"
End Function


I just tried it on a file that is larger than 135KB and had no problem
-- I got the full 279KB. Have you checked the length of the returned
data, or are you just getting 135KB in the output file? That is, are
you sure it's XMLHTTP that is the problem?


================ wrote:


I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.


Any suggestions?


My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.


----- code follows -----


Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte


Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request


'Wait for request to finish
Do While oXMLHTTP.readyState < 4
DoEvents
Loop


oResp = oXMLHTTP.responseBody 'Returns the results as a byte array


'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) < "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF


'Clear memory
Set oXMLHTTP = Nothing
End Function


----- end code -----


Thanks in advance,
John Warren


Randy,

Thanks, I tried your function on a longish file and it seems to work.
I'm at home now and need to be at work to run a better test, but I'll
try it and let you know how things work out. I'll also check the
length of the string returned by the original version.

John- Hide quoted text -

- Show quoted text -


OK, I took a better look at the page I was trying to download and I
now see that it's more complicated than I realized. I thought I was
attempting a simple download, but the page was actually some kind of
aspx thing that runs a javascript when the "link" to the target file
is clicked. So when I tried to download the file via xmlhttp I was
actually getting the aspx page instead of the file I wanted. Xmlhttp
is working correctly, but I haven't got a clue what I need to do
automate my download.

If anyone has any suggestions I would interested in seeing them. I'm
thinking about giving up at this point, since I can see I am in over
my head.

John

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXML2.XMLHTTP: "Access is Denied" - works on IE 6 SP1 but not SP2 p3plyr Excel Programming 0 April 17th 07 10:38 PM
MSXML2.XMLHTTP Works with IE6, IE6 SP 1 but not with IE6 SP 2 - wh p3plyr Excel Programming 1 April 17th 07 06:12 PM
MSXML2.DOMDocument [email protected] Excel Programming 1 April 10th 07 09:54 AM
Download files using MSXML2.XMLHTTP p3plyr Excel Programming 0 March 23rd 07 06:25 AM
MSXML2.XMLHTTP clear excel cache/memory (?) p3plyr Excel Programming 3 March 21st 07 10:15 AM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"