Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WinHTTPRequest

Status
Not open for further replies.

mlabac

Programmer
Jan 22, 2004
23
0
0
US
I have written the following procedure to retrieve a .csv file from a website. The procedure works fine, as I use it at other sites to download .csv files on a scheduled basis.

The problem with this particular site, is that for security reasons they change the name of the daily. Today the file might be called PriceList_YWQBW.csv, while tomorrow the file will be something different so I can not point to the URL with the GET command.

To manually go and download the file I am traversed through a log in page and by clicking on a series of links I am presented with a pop up page that says “right click to save target.” I am thinking there has to be a way to traverse through these pages in code.

Thoughts?

Thanks in advance

Private Sub Form_Load()
' Create an instance of the WinHTTPRequest ActiveX object.
Set http = New WinHttpRequest

'HttpRequest SetCredentials flags.
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0

' Switch the mouse pointer to an hourglass while busy.
MousePointer = vbHourglass

' Open an HTTP connection.
http.Open "GET", " False

'Set credentials for server.
http.SetCredentials "UserName", "Password", _
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER

' Send the HTTP Request.
http.Send

' Load the contents of the file into a string variable.
file_contents = http.ResponseText

Set http = Nothing

' Save the file

If Not file_contents = "" Then
Open "\\Local Path\Catalog.csv" For Output As #1
Print #1, file_contents
End If

Close

' Switch the mouse pointer back to default.
MousePointer = vbDefault


' Close the form.
Unload Me

End Sub
 
Maybe you can use shdocvw.dll (Microsoft Internet Controls)? These will allow you to create an IE instance (or get an existing IE instance) and manipulate it programmatically.

Maybe you can grab the page that pops up, since your program knows when it happens, and use the Navigate2 method to move through your pages.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top