example_of_data_access_from_c_c
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | example_of_data_access_from_c_c [2018/12/11 12:14] (current) – created emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== An example of data access from C/C++ ====== | ||
+ | |||
+ | An example of C code for executing a query to the WebHMI API. | ||
+ | <code C> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | using namespace std; | ||
+ | size_t write_func(void *ptr, size_t size, size_t nmemb, void *userdata) | ||
+ | { | ||
+ | cout.write( (char * ) ptr, size*nmemb); | ||
+ | return size * nmemb; | ||
+ | } | ||
+ | |||
+ | int main(int argc, char** argv) { | ||
+ | | ||
+ | CURL *curl; | ||
+ | CURLcode res; | ||
+ | |||
+ | char errorBuffer[CURL_ERROR_SIZE]; | ||
+ | |||
+ | // Create the GET request | ||
+ | struct curl_slist *headers = NULL; | ||
+ | headers = curl_slist_append(headers, | ||
+ | headers = curl_slist_append(headers, | ||
+ | headers = curl_slist_append(headers, | ||
+ | headers = curl_slist_append(headers, | ||
+ | headers = curl_slist_append(headers, | ||
+ | |||
+ | |||
+ | // Init CURL | ||
+ | curl = curl_easy_init(); | ||
+ | |||
+ | if(curl) { | ||
+ | curl_easy_setopt(curl, | ||
+ | curl_easy_setopt(curl, | ||
+ | curl_easy_setopt(curl, | ||
+ | curl_easy_setopt(curl, | ||
+ | |||
+ | // Attempt to Connect the Server | ||
+ | res = curl_easy_perform(curl); | ||
+ | |||
+ | if (res == CURLE_OK) { | ||
+ | long http_code = 0; | ||
+ | curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, | ||
+ | if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK) { | ||
+ | cout << endl << " | ||
+ | } else { | ||
+ | cout << endl << " | ||
+ | } | ||
+ | } else { | ||
+ | cout << " | ||
+ | } | ||
+ | |||
+ | // Close the connection | ||
+ | curl_easy_cleanup(curl); | ||
+ | } | ||
+ | | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
example_of_data_access_from_c_c.txt · Last modified: 2018/12/11 12:14 by emozolyak