[英]Dynamic URL with curl C++
这是我的curl GET查询的C ++代码(在QT5中)
CURL *curl;
CURLcode res;
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/?site=http://google.fr&name=test");
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.42.0");
此代码完美地工作! 请求启动。
我想更改应用程序领域的路径。
我通过此变量获取域
QString domain = ui->editDomain->text();
我试过了:
curl_easy_setopt(curl, CURLOPT_URL, domain + "?site=http://google.fr&name=test");
但是这里查询没有启动! 而且我不明白为什么...而且编译时没有错误
curl
函数采用C字符串。 domain + "?site=http://google.fr&name=test"
提供了一个QString
,该函数不知道如何处理。 您需要做的是将生成的QString
转换为c字符串。 你可以那样做
curl_easy_setopt(curl, CURLOPT_URL, (domain + "?site=http://google.fr&name=test").toUtf8().constData());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.