int main(void) { const char* server_target = "https://*****:*****@tenghuanhe.cloudant.com/cctv10"; int i; char* data = NULL; long data_len = 0; pt_node_t* bulk = pt_map_new(); pt_map_set(bulk, "name", pt_string_new("IBM")); if (bulk) { data = pt_to_json(bulk, 2); if (data) data_len = strlen(data); } CURL *curl_handle = curl_easy_init(); CURLcode res; struct curl_slist* header_list = NULL; header_list = curl_slist_append(header_list, "Content-Type: application/json"); curl_easy_setopt(curl_handle, CURLOPT_URL, server_target); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, header_list); curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, data_len); curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data); // curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 3L); res = curl_easy_perform(curl_handle); printf("%d\n", res); curl_easy_cleanup(curl_handle); return 0; }
//------------------------------------------------ //-- S t a t i c I m p l e m e n t a t i o n -- //------------------------------------------------ static void conceptualize(m2pp::request& req) { printf("Conceptualize\n"); //const char* cand = chb_rq_param_get(req,"candidates"); char* cand = (char* )"Amazon|Apple|Steve Jobs|Google|United States|America|Yahoo|iPhone|iPad"; char* cand_copy = NULL; if (!cand) cand_copy = strdup(""); else cand_copy = strdup(cand); SnippetList candidates; split_into_vector(candidates,cand_copy); ResolvedConceptList concepts; __cr->resolve(candidates,concepts); pt_node_t* result = pt_array_new(); for(ResolvedConceptList::const_iterator ii = concepts.begin(); ii != concepts.end(); ii++) { resolved_concept_t conc = *ii; pt_node_t* entry = pt_map_new(); pt_map_set(entry,"text_rep", pt_string_new(conc.text_rep)); pt_map_set(entry,"concept", pt_string_new(conc.canonical)); pt_map_set(entry,"score", pt_integer_new(conc.score)); cout << "Concept:" << conc.text_rep << ":" << conc.canonical << ":" << conc.score << endl; pt_array_push_back(result,entry); } pt_node_t* payload = pt_map_new(); pt_map_set(payload,"payload",result); char* json_str = pt_to_json(payload,0); pt_free_node(payload); ReqRes rr; rr.req = req; rr.res = json_str; free(json_str); __res_queue.enqueue(rr); }