Answer the question
In order to leave comments, you need to log in
Beginner troubles or curl_easy_perform -> segfault
Prehistory: I don't have average knowledge in C either. By the will of fate, it so happened that I had to write a simple file loader in C. There are suspicions that I did not read the cUrl documentation correctly, but took an example from their documentation.
CURL *curl;
curl = curl_easy_init();
if(!curl) {
fprintf(stderr, "curl init() failed: ");
return token;
}
// используется библиотека cJSON для чтения конфига
const char * password = cJSON_GetObjectItem(service,"password")->valuestring;
const char * login = cJSON_GetObjectItem(service,"login")->valuestring;
const char * url = cJSON_GetObjectItem(service,"url")->valuestring;
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HEADER, "Content-Type: text/xml; charset=UTF-8");
// тут генерируется xml, читается файл с xml шаблоном запроса, логина и пароля заменяются в нужных местах
const char * xml = generate_xml(login, password);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xml);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE , strlen(xml));
// хотелось бы конечно писать результат, но для начала хоть запрос бы выполнить
//curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
//curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
CURLcode res;
res = curl_easy_perform(curl);
printf("break!\n");
exit(0);
Answer the question
In order to leave comments, you need to log in
the problem was that the url was https, and without specifying the path to CURLOPT_CAINFO and setting CURLOPT_SSL_VERIFYHOST = 0, curl crashed with segfault
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question