Skip to content

Instantly share code, notes, and snippets.

@pratyakshs
Created November 28, 2015 18:53
Show Gist options
  • Save pratyakshs/c3eca8df4773fb386514 to your computer and use it in GitHub Desktop.
Save pratyakshs/c3eca8df4773fb386514 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <curl/curl.h>
#include <json/json.h>
#include <string.h>
// compile using: gcc curl-example.c -ljson -lcurl -lb64
char * host = "0.0.0.0:17070";
char * getRowCol(char * tableName, char * rowName, char * colName) {
CURL *curl;
CURLcode res;
char buffer[500];
char errorBuffer[500];
curl = curl_easy_init();
if(curl) {
char url[200];
strcpy(url, host);
strcat(url, "/");
strcat(url, tableName);
strcat(url, "/");
strcat(url, rowName);
strcat(url, "/");
strcat(url, colName);
curl_easy_setopt(curl, CURLOPT_URL, url);
printf("sdfsdf\n");
res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
if (res != CURLE_OK)
{
fprintf(stderr, "Failed to set error buffer [%d]\n", res);
return 0;
}
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
if (res != CURLE_OK) {
fprintf(stderr, "Failed to set write data [%s]\n", errorBuffer);
return 0;
}
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
printf("sfsdf\n");
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
printf("STARTE%sD\n", buffer);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
int main(void)
{
getRowCol("praty", "row1", "c1");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment