Lasso Soft Inc. > Home

[ curl_easy_init ]

Method

[curl_easy_init] starts a libcurl easy session.

This function must be the first function to call, and it returns a [curltoken] that you must use as input to other easy-functions. [curl_easy_init] initializes curl and this call MUST have a corresponding call to [curl_easy_cleanup] when the operation is complete.

If you did not already call [curl_global_init], [curl_easy_init] does it automatically. This may be lethal in multi-threaded cases, since [curl_global_init] is not thread-safe, and it may result in resource problems because there is no corresponding cleanup.

You are strongly advised to not allow this automatic behaviour, by calling [curl_global_init] yourself properly.

  • Syntax
curl_easy_init
Examples
  • Intermediate

To obtain the HTTP header from a curl operation

Code

local(ctoken, err, data, headerBytes = bytes, bodyBytes = bytes, ready = false)

#ctoken = curl_easy_init
#err = curl_easy_setopt(#ctoken, curlopt_url, "http://www.lassosoft.com/")
while(!#ready) => {
     #data = curl_multi_perform(#ctoken)
     #data->second->isa(::bytes) ? #headerBytes->append(#data->second)
     #data->last->isa(::bytes) ? #bodyBytes->append(#data->last)
     #ready = !#data->first
     !#ready ? sleep(10)
}
//#headerBytes contains the http headers returned
//#bodyBytes contains the data returned from the request

#headerBytes     //shows the headerbytes

Result

HTTP/1.1 200 OK
Date: Sun, 13 Feb 2011 12:06:49 GMT
Server: Apache/2.0.63 (CentOS)
MIME-Version: 1.0
Content-Length: 12220
Connection: close
Content-Type: text/html; charset=utf-8

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft