1
有了这个代码,我使用的libcurl和写入数据到MySQL(在Web服务器完成)发送字符串添加到Web服务器。 我的问题是,这个函数的每次调用程序启动与网络服务器一个新的密钥交换。我想与服务器建立持久连接。 我在这里搜索和网络已经和没有找到任何令人满意的解决方案。 多处理器和强迫保持活着还是打开一个新的连接。保活卷曲Çhtttps POST
以下是我的代码建立SSL连接:
CURL *curl;
CURLcode res;
res = curl_global_init(CURL_GLOBAL_DEFAULT); // Check for errors
if(res != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed: %s\n",
curl_easy_strerror(res));
return 1;
}
// curl handler
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, STRING);
curl_easy_setopt(curl, CURLOPT_URL, "https://IP/something/something.php");
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //verbose output activated
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type: application/json"); // type JSON
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// Perform the request, res will get the return code
res = curl_easy_perform(curl);
// Check for errors
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
// cleanup
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
感谢您使看起来相当dragosht代码 – gamejunkie959