将变量传递给curl_easy_setopt C++

Gra*_*ses 0 c++ curl libcurl

如何将全局变量传递给curl_easy_setopt

int agent_num = rand() % 100000;
std::string agent_name = "https://127.0.0.1:443/agent/" + agent_num;

curl_easy_setopt(curl, CURLOPT_URL, agent_name);
Run Code Online (Sandbox Code Playgroud)

我尝试过不同的事情,他们给了我一个段错误任何帮助,谢谢!

A. *_*lle 5

std::string不会自动转换为char *. 使用它的c_str()方法:

curl_easy_setopt(curl, CURLOPT_URL, agent_name.c_str());