01/25/2018, 6:27 PM
I’m a little further in my tinkering/understanding. I’m now trying to create a small Kotlin example using libcurl but I’m getting a runtime error:
SFO1212474815A:easycurl 212474815$ kotlinc curl.kt -library curlklib -o kurl
KtFile: curl.kt
ld: warning: directory not found for option '-L/opt/local/lib'
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
SFO1212474815A:easycurl 212474815$ ./kurl.kexe
Download from URL
Error performing CURL download: CPointer(raw=0x10e711808)
My curl.kt file has:
import curl.*

fun main(args: Array<String>) {
println("Download from URL")
val url = "<>"
val curl = curl_easy_init();
var result :CURLcode;

result = curl_easy_setopt(curl, CURLOPT_URL, url);
if(result != CURLE_OK) {println("Error setting URL for download: ${curl_easy_strerror(result)}"); return;}

result = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
if(result != CURLE_OK) {println("Error setting CURL FOLLOWLOCATION option to true for download: ${curl_easy_strerror(result)}"); return;}

result = curl_easy_perform(curl);
if(result != CURLE_OK) {println("Error performing CURL download: ${curl_easy_strerror(result)}"); return;}

I’m not understanding what the error is telling me. Am I supposed to do something special to pass the curl object or url string into the native API calls?
I’m thinking the error result is returned as a raw CPointer and I just need to convert it to a kstring or something but how do I do that without knowing the length?
Do I make a utility function that converts by scanning for a null terminator?
I figured it out!!! The sample code I copied from has a small bug.
The bug was in the error checking logic which I’ve changed to this:
result = curl_easy_perform(curl);
if(result != CURLE_OK) {
val emsg = curl_easy_strerror(result);
println("Error performing CURL download: ${emsg?.toKString()}");
Once I corrected the error checking logic it was obvious why the example was failing. The error reported was:
SFO1212474815A:easycurl 212474815$ ./kurl.kexe
Download from URL
Error performing CURL download: Couldn't resolve host name
I was behind an http proxy! My next question would be how would I configure proxy settings in such an app?
I suppose I would have to configure the proxy manually through curl?