Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grab HTML site with password
Message
From
14/06/2009 18:01:11
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Grab HTML site with password
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2003
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01405925
Message ID:
01405925
Views:
129
From the desktop, I am grabbing an XML file that is located at a specific URL, let's say
https://mydomain.org/coolstuff/myformdata_full.xml

I have been using this code I grabbed from an old MSDN article, I trimmed the code a bit for posting and it is below. But now the URL has a challenge and response, and I need to feed it the username and password. Oh wise people, how can I do that?

Thanks

* ==============
* code for no password in use now:

lcUrlName = tURL

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
#DEFINE CR CHR(13)

IF NOT FILE("data.dbf")
CREATE TABLE data (MEMO M)
ELSE
USE data
ENDIF
APPEND BLANK

* what application is using Internet services?
sAgent = "VPF 9.0"

hInternetSession = InternetOpen(sAgent, INTERNET_OPEN_TYPE_PRECONFIG, ;
'', '', SYNCHRONOUS)

IF hInternetSession = 0
WAIT WINDOW "Internet session cannot be established" TIME 2
RETURN 0
ENDIF

hUrlFile = InternetOpenUrl(hInternetSession, UrlName, '', ;
0, INTERNET_FLAG_RELOAD, 0)

DO WHILE .T.
* set aside a big buffer
sReadBuffer = SPACE(32767)
lBytesRead = 0
m.OK = InternetReadFile(hUrlFile, @sReadBuffer, ;
LEN(sReadBuffer), @lBytesRead)

REPLACE mjedata.MEMO WITH sReadBuffer ADDITIVE

* error trap - either a read failure or read past eof()
IF m.OK = 0 OR lBytesRead = 0
EXIT
ENDIF
ENDDO

* close all the handles we opened
=InternetCloseHandle(hUrlFile)
=InternetCloseHandle(hInternetSession)

* return the number of bytes read
RETURN LEN(hurl.memo)
Next
Reply
Map
View

Click here to load this message in the networking platform