提交 5498b6cc 编写于 作者: P Ping Xiao

test: add restful demo for tq

上级 e430675c
......@@ -14,15 +14,17 @@
*/
// TAOS standard API example. The same syntax as MySQL, but only a subset
// to compile: gcc -o tqdemo tqdemo.c -ltaos
// to compile: gcc -o tqdemo tqdemo.c -ltaos -lcurl
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h> // TAOS header file
#include <curl/curl.h>
void print_results(TAOS *taos, char *qstr);
void restful_demo(char *host, char *qstr);
int main(int argc, char *argv[]) {
char qstr[1024];
......@@ -60,10 +62,13 @@ int main(int argc, char *argv[]) {
}
// query data
print_results(taos, "select * from tq_test.ps");
// print_results(taos, "select * from tq_test.ps");
taos_close(taos);
taos_cleanup();
// restful demo
restful_demo(argv[1], "show topics");
}
......@@ -92,3 +97,26 @@ void print_results(TAOS *taos, char *qstr) {
}
taos_free_result(res);
}
void restful_demo(char *host, char *qstr) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl == NULL) {
printf("failed to create curl connection");
return;
}
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Basic cm9vdDp0YW9zZGF0YQ==");
char url[1000];
sprintf(url, "%s:6041/rest/sql", host);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, qstr);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册