组合字符串不适用于 libCurl,C++
Combined string isn't working for libCurl in C++
基本上,我现在使用的程序/代码是从PHP脚本返回消息。我遇到的问题是,当我为 URL 提供组合字符串时,它不会返回任何内容。但是当我手动输入它时,它会返回正确的信息。这是我在下面使用的代码:
std::string Login(std::string uname, std::string pass)
{
CURL* curl;
CURLcode res;
std::string readBuffer;
std::string path = "localhost/files/login.php?username=" + uname + "&password=" + pass;
std::cout << uname << " " << pass;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "localhost/files/login.php?username=123&password=123");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
return readBuffer;
}
return "Failed";
}
这种方式之所以有效,是因为我手动输入了URL,但是当我这样做时,它不会返回任何内容:
std::string path = "localhost/files/login.php?username=" + uname + "&password=" + pass;
curl_easy_setopt(curl, CURLOPT_URL, path);
我不确定我是否使用了错误的变量或其他变量。我是使用PHP和libCurl以及任何与网络相关的事物的新手。
CURLOPT_URL
期望以 C 样式的 null 结尾的char*
字符串指针作为输入,而不是std::string
。 您可以使用std::string::c_str()
方法从std::string
获取兼容的const char*
指针:
curl_easy_setopt(curl, CURLOPT_URL, path.c_str());
相关文章:
- 发送一个带有libcurl C++问题的帖子请求:s
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 在 libcurl 连接池中预创建连接
- libcurl 和 DNS ttl 中的内部连接管理
- 如何在 cmake 库中包含 libcurl
- 如何应用 libcurl 的持久连接选项
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 组合字符串不适用于 libCurl,C++
- Poloniex API "Invalid command" c++ libcurl
- libcurl :显示正在运行的上传和下载速率
- c++ libCurl :如何使用libCurl接受过期的证书
- libcurl :C++处理多个异步请求
- 现代C++的libcurl和JSON问题
- 使用 Libcurl 库进行文件下载
- 如何在C++生成器中使用libcurl
- Libcurl c++ "undefined reference to" (Windows/MinGW/g++)
- 如何使用 libcurl 在本地 IP 上获取 HTML?
- 如何将带有 -F 选项的 curl 命令转换为 libcurl
- 如何使用 libCurl 将访问令牌发送到服务器 API
- C++ libcurl - 无法从 URL 检索整个 html 内容