Re: getting data from password prot. webpage

new topic     » goto parent     » topic index » view thread      » older message » newer message

Mark Gabor wrote:

> So, I have a question: is it possible to get data (the complete http page)
> from
> a 
> password protected webpage? Ofcourse I know the login data and the page using
> 
> php POST authentication. 

Sure. Here's an extract of code I use, using eulibcURL.

atom curl_handle
atom errp -- curl error
errp = allocate(CURL_ERROR_SIZE)

if  curl_global_init(CURL_GLOBAL_ALL) != 0 then
	warnErr("Could not initialise libCurl\n\nContinue?")
end if
curl_handle = curl_easy_init()
void = curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errp)
void = curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1)

void = curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP)
void = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "")
void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE,
"C:\\EUPHORIA\\Direct_cookies")
void = curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR,
"C:\\EUPHORIA\\Direct_cookies")
void = curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Opera/9.21 (Windows NT
5.1; U; en)")

void = curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0)
-- CURLOPT_CAINFO and CURLOPT_CAPATH would be used to point to certificates,
-- but the line above says not to verify the SSL certificate

-- put your logon sequence into form_data
if sequence (form_data) then
	void = curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, form_data)
else
	void = curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1)
end if

void = curl_easy_setopt(curl_handle, CURLOPT_URL, url)
if sequence(form_data) then
	showMessage(sprintf("Downloading file %s : %s",{url,form_data}))
else
	showMessage(sprintf("Downloading file %s",{url}))
end if
buffer = curl_easy_perform_ex(curl_handle)
if atom(buffer) then
showMessage(sprintf("Error '%s' downloading file", {peek_sequence(errp,
CURL_ERROR_SIZE) } ) )
else
	--process the data
end if

curl_easy_cleanup(curl_handle)
curl_global_cleanup()
free(errp)


-- 
Craig
Euphoria friendly webhosting: http://www.wazu.jp/hosting/euphoria.html

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu