[英]Dynamic URL with curl C++
Here is my C++ code for curl GET query (in QT5) 这是我的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");
This code works perfectly! 此代码完美地工作! the request is launched.
请求启动。
I would like to change the path of the field of the application. 我想更改应用程序领域的路径。
I get the domain by this variable 我通过此变量获取域
QString domain = ui->editDomain->text();
I tried: 我试过了:
curl_easy_setopt(curl, CURLOPT_URL, domain + "?site=http://google.fr&name=test");
But here the query is not launching! 但是这里查询没有启动! And I do not understand why... And no error at compilation
而且我不明白为什么...而且编译时没有错误
curl
functions take a c-string. curl
函数采用C字符串。 domain + "?site=http://google.fr&name=test"
gives you a QString
which the function doesn't know how to handle. domain + "?site=http://google.fr&name=test"
提供了一个QString
,该函数不知道如何处理。 What you need to do is convert the resulting QString
into a c-string. 您需要做的是将生成的
QString
转换为c字符串。 You can do that like 你可以那样做
curl_easy_setopt(curl, CURLOPT_URL, (domain + "?site=http://google.fr&name=test").toUtf8().constData());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.