我正在使用 CurlPP 通过使用https://ipify.org的 API 获取网络的公共 IP 地址 我的函数工作正常,但是,它只在调用 4-6 次时才有效。我在 while 循环中调用该函数以检查 IP 地址的更改。(有时会工作 4 次,有时会工作 5 或 6 次)。之后,什么也没有发生,没有输出,什么都没有,只是光标在终端中闪烁,没有错误或任何东西!
std::string getIPAddress()
{
try
{
curlpp::Cleanup myCleanup;
{
std::ostringstream ip_address_stream;
ip_address_stream << curlpp::options::Url("http://api.ipify.org");
ip_address = ip_address_stream.str();
return ip_address;
}
}
catch(curlpp::RuntimeError &e)
{
std::cout << e.what() << std::endl;
}
catch(curlpp::LogicError &e)
{
std::cout << e.what() << std::endl;
}
}