Task

Send a GET request to obtain the resource located at the URL "https://www.w3.org/", then print it to the console.

Checking the host certificate for validity is recommended.

Do not authenticate. That is the subject of other tasks.

Readers may wish to contrast with the HTTP Request task, and also the task on HTTPS request with authentication.


/* https.wren */
 
var CURLOPT_URL = 10002
var CURLOPT_FOLLOWLOCATION = 52
var CURLOPT_ERRORBUFFER = 10010
 
foreign class Curl {
    construct easyInit() {}
 
    foreign easySetOpt(opt, param)
 
    foreign easyPerform()
 
    foreign easyCleanup()
}
 
var curl = Curl.easyInit()
if (curl == 0) {
    System.print("Error initializing cURL.")
    return
}
curl.easySetOpt(CURLOPT_URL, "https://www.w3.org/")
curl.easySetOpt(CURLOPT_FOLLOWLOCATION, 1)
curl.easySetOpt(CURLOPT_ERRORBUFFER, 0) // buffer to be supplied by C
 
var status = curl.easyPerform()
if (status != 0) {
    System.print("Failed to perform task.")
    return
}
curl.easyCleanup()