【发布时间】:2021-05-04 14:28:04
【问题描述】:
#include <curl/curl.h>
#include <cstdlib>
#include <iostream>
int rad = rand() % 100000;
std::string agent_name = "https://127.0.0.1:443/agent/" + rad;
std::string full_agent_name = agent_name + std::to_string(rad);
int main(int argc, char **)
{
CURLcode ret;
CURL *curl;
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(curl, CURLOPT_URL, full_agent_name.c_str());
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
我不明白为什么这是段错误。我是 C++ 新手,只知道 python3 任何帮助都会非常棒,祝你有美好的一天!
【问题讨论】:
-
将
rad添加到agent_name和full_agent_name有什么意义?似乎您根本不应该将rad添加到agent_name:std::string agent_name = "https://127.0.0.1:443/agent/"; std::string full_agent_name = agent_name + std::to_string(rad); -
雅哈哈,我应该更好地审查它,错字:(
标签: c++ curl segmentation-fault