Re: libcurl - help needed

new topic     » goto parent     » topic index » view thread      » older message » newer message
jmduro said...

I can access https sites but there are some functionnalities I can't get to work:

  • cookies (there is no error but the list of cookies remains empty)
  • recover HTML body (as with Ray's curl_easy_perform_ex)

To recover the HTML body from the call to curl_easy_perform(), you need to establish a write function via curl_easy_setopt() that collects the data.

This example is untested, but it's how I've done this in C code that uses cURL.

include std/eumem.e 
include std/machine.e 
 
function curl_write_callback( atom ptr, atom size, atom nmemb, atom userdata ) 
 
    atom realsize = size * nmemb 
    sequence data = peek({ ptr, realsize }) 
 
    eumem:ram_space[userdata] = append( eumem:ram_space[userdata], data ) 
 
    return realsize 
end function 
 
public function curl_easy_perform_ex( atom handle ) 
 
    atom write_cb = call_back( routine_id("curl_write_callback") ) 
    curl_easy_setopt( handle, CURLOPT_WRITEFUNCTION, write_cb ) 
 
    atom userdata = eumem:malloc( "" ) 
    curl_easy_setopt( handle, CURLOPT_WRITEDATA, userdata ) 
 
    atom result = curl_easy_perform( handle ) 
    sequence content = eumem:ram_space[userdata] 
 
    eumem:free( userdata ) 
 
    return {result,content} 
end function 

-Greg

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

Search



Quick Links

User menu

Not signed in.

Misc Menu