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

Internet

How do I programmatically Load a Web Page without using Internet Explorer? by wgcs
Posted: 11 Jan 03

This function that I picked up from somewhere or other will do it for you!

This method doesn't use an Internet Explorer ActiveX control, but it does require Api functions contained in DLL's that were originally installed with IE (probable v3.0).  
These are now (WinME/2k/XP/+) standard, I believe.
If anyone knows otherwise, let me know!


* readurl.prg 06-Mar-98

* 06-Mar-98 pulled from Q174524 on March 98 Technet CD
* 06-Mar-98 bug fixed about the length of the sReadBuffer

*Any Internet or intranet URL can be passed as a parameter. Microsoft.com
*was chosen for this example.

*Note that Microsoft Internet Explorer must be installed on the computer.

* passed: URLName, in the form "http://www.microsoft.com"
*
* returns: the content of the URL
*
* usage:
*
*  uWebContent = ReadURL( "http://www.microsoft.com" )
*  uWebContent = ReadURL( "http://www.SomeSite.com/SomeJPG.jpg" )
*
* notes:
* 1 - IE does not need to be running to use this, but must be installed

LPARAMETERS pcUrlName

DECLARE INTEGER InternetOpen IN wininet.DLL STRING sAgent, ;
   INTEGER lAccessType, STRING sProxyName, ;
   STRING sProxyBypass, INTEGER lFlags

DECLARE INTEGER InternetOpenUrl IN wininet.DLL ;
   INTEGER hInternetSession, STRING sUrl, STRING sHeaders, ;
   INTEGER lHeadersLength, INTEGER lFlags, INTEGER lContext

DECLARE INTEGER InternetReadFile IN wininet.DLL INTEGER hfile, ;
   STRING @sBuffer, INTEGER lNumberofBytesToRead, INTEGER @lBytesRead

DECLARE short InternetCloseHandle IN wininet.DLL INTEGER hInst

#DEFINE INTERNET_OPEN_TYPE_PRECONFIG 0
#DEFINE INTERNET_OPEN_TYPE_DIRECT 1
#DEFINE INTERNET_OPEN_TYPE_PROXY 3
#DEFINE SYNCHRONOUS 0
#DEFINE INTERNET_FLAG_RELOAD 2147483648

local lsAgent, lhInternetSession, lhUrlFile, llOk, lnOk, lcRetVal, lcReadBuffer, lnBytesRead

* what application is using Internet services?
lsAgent = "VFP"

lhInternetSession = InternetOpen( lsAgent, INTERNET_OPEN_TYPE_PRECONFIG, '', '', SYNCHRONOUS )

IF lhInternetSession = 0
   WAIT WINDOW "Internet session cannot be established" TIME 2
   RETURN .null.
ENDIF

lhUrlFile = InternetOpenUrl( lhInternetSession, pcUrlName, '', 0, INTERNET_FLAG_RELOAD, 0 )

IF lhUrlFile = 0
   * URL cannot be opened
   RETURN .null.
ENDIF

lcRetVal = ""
llOk = .t.

DO WHILE llOK
   * set aside a big buffer
   lsReadBuffer = SPACE(32767)
   lnBytesRead = 0
   lnOK = InternetReadFile( lhUrlFile, @lsReadBuffer, LEN(lsReadBuffer), @lnBytesRead)
    
   if ( lnBytesRead > 0 )
      lcRetVal = lcRetVal + left( lsReadBuffer, lnBytesRead )
   endif

   * error trap - either a read failure or read past eof()
   llOk = ( lnOK = 1 ) and ( lnBytesRead > 0 )
ENDDO

* close all the handles we opened
InternetCloseHandle( lhUrlFile )
InternetCloseHandle( lhInternetSession )

* return the URL contents
RETURN lcRetVal

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

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