Call.c [src/java/client/example] Revision:   Date:
#include <string.h>
#include <curl/curl.h>

// compile: gcc Call.c -lcurl

int main() {
  CURL *curl;
  CURLcode res;
  struct curl_slist *headers = NULL;

  curl = curl_easy_init();
  if (curl) {
    const char *req = 
        "{ "
        "  metainfo: {},"
        "  parameter: [ "
        "    { name: \"temp\","
        "      value: 25 "
        "    } "
        "  ] "
        "}";
    
    const char *url = "http://localhost:8080/csip-example/m/simpleservice/1.0";

    headers = curl_slist_append(headers, "content-type:application/json");
    headers = curl_slist_append(headers, "accept:application/json");

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(req));
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    res = curl_easy_perform(curl);
    if (CURLE_OK != res) {
      printf("Error: %s\n", strerror(res));
      return 1;
    }
    curl_easy_cleanup(curl);
    curl_slist_free_all(headers);
  }
  return 0;
}