Author Topic: C BASIC - cURL  (Read 4832 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
C BASIC - cURL
« on: December 01, 2013, 07:35:55 AM »
This is a wget like example of getting the default web page on my local Apache server.

Code: C
  1. // C BASIC - cURL (wget example)
  2. // gcc cbcurl.c -lcurl -o cbcurl
  3.  
  4. #include <stdio.h>
  5. #include <curl/curl.h>
  6. #include "cbasic.h"
  7.  
  8. MAIN
  9. BEGIN_FUNCTION
  10.   DIM AS CURL PTR curl;
  11.   DIM AS CURLcode res;
  12.   curl = curl_easy_init();
  13.   IF (curl) THEN
  14.     curl_easy_setopt(curl, CURLOPT_URL, "localhost/index.html");
  15.     res = curl_easy_perform(curl);
  16.     curl_easy_cleanup(curl);
  17.   END_IF
  18.   RETURN(0);
  19. END_FUNCTION
  20.  

jrs@laptop:~/C_BASIC/xlate$ gcc cbcurl.c -lcurl -o cbcurl
jrs@laptop:~/C_BASIC/xlate$ ./cbcurl
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
jrs@laptop:~/C_BASIC/xlate$
« Last Edit: July 18, 2015, 12:20:38 AM by John »