INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Storing info from URL call

Storing info from URL call

(OP)
Hi all, and especially Zebula8 who wrote the below:

CODE

Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_OPEN_TYPE_PROXY = 3
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
Public Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sbuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long



Private Function GetFile(ByVal sURL As String) As Integer
' Reads the data from a web page to a buffer and downloads it to a user's machine
'
'
Dim hOpen As Long
Dim hFile As Long
Dim sbuffer As String
Dim Ret As Long
'Dim lFilenumber As Long
Dim oFS As Object
Dim oTxtStream As Object

On Error GoTo GetFile_Error

GetFile = 0

 ' create a buffer for the file we're going to download
' you'll have to decide ahead of time how large the file that is to be downloaded is and adjust accordingly
 sbuffer = Space(2000)
 
 ' create an internet connection
 hOpen = InternetOpen("userAgent", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
 
 ' open the url
 hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)

 
 If hFile <> 0 Then
     ' read the bytes of the file
     InternetReadFile hFile, sbuffer, 2000, Ret
 

     ' clean up
     InternetCloseHandle hFile
     InternetCloseHandle hOpen
     
    ' create file system object
    Set oFS = CreateObject("Scripting.FileSystemObject")
    
    ' create a textstream - parameter of true means it will be unicode
    Set oTxtStream = oFS.CreateTextFile("c:\PathToFile\myFile.txt", True)
    
    ' now we have our textstream we can write to it and then close it
    oTxtStream.Write Trim$(sbuffer)
    oTxtStream.Close

    Set oTxtStream = Nothing
    Set oFS = Nothing
    GetFile = 1
 End If

   On Error GoTo 0
   Exit Function

GetFile_Error:

    MsgBox "Error " & Err.Number  ' put your own handling here  
End Function

Many thanks for this code, I have used it to build a 'Web Task Scheduler' that calls .asp scripts to perform a function and writes the results to screen and details to a text log.  It's running about six scripts varying from daily to every minute and it works great when it's running from my home pc.
But I uploaded it my server and installed it and it works fine for any URLs that are elsewhere on the net but doesn't return anything from any script stored on the server itself.
It doesn't use URL look up but the direct IP address, ie 85.215.12.32, (there is no actual URL for the server), but this made no difference when it was running off a different machine.
But it's OK to call a script on another URL that then does a GET request of the server script, but not a redirect.

Any hints at how to get round this?  

RE: Storing info from URL call

Have you tried using 127.0.0.1 for these scripts?

RE: Storing info from URL call

(OP)
Brilliant bit of lateral thinking there young sir/madam!!

Works a treat, (altho I have to admit I didn't have a clue what you were talking about at first!)

Have a star.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close