Libcurl请求没有结果
Libcurl request no result
我在c++中使用libcurl扩展。我发送一个请求到elasticsearch服务器,但结果是' null '。我在PHP中重建了curl请求,它工作了。我怎样才能从web服务器得到结果?
CURL *curl;
CURLcode res;
std::stringstream ss_url;
ss_url << "http://IP/newgame/player/2/_update";
char *post_url = const_cast<char*>(ss_url.str().c_str());
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, post_url);
curl_easy_setopt(curl, CURLOPT_PORT, 9200);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl,CURLOPT_POSTFIELDS, '{ "doc": { "x": 555555, "y": 287273 }}');
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
编辑:我已经尝试记录curl的答案。但是文件是空的
FILE *curllog = fopen("/home/elasticsearch_curl.log", "w+");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, curllog);
检查post_url强制转换是否有问题,将其替换为实际字符串。in curl_set_opt of CURLOPT_URL
curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com");
这可能是问题所在。这对我很有效。包括在curl_easy_perform之后进行调试和检查。
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform()failed:%sn",curl_easy_strerror(res));}
一个有效的GET示例:https://gist.github.com/k3ut0i/737b6d19713ef5aa0a74
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- valgrind-hellgrind与泄漏检查的结果不同
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 用C++20 fmt限制结果的总大小
- 如何返回一个类的两个对象相加的结果
- 如何在boost beast http请求中设置http头
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- 发送一个带有libcurl C++问题的帖子请求:s
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 序列化,没有库的整数,得到奇怪的结果
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 在更改for循环的第三部分后,未使用for循环结果
- 在多个核心中处理一个HTTP请求
- 使用++运算符会导致意外的结果
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 多对多请求/结果模式的模式
- 使用c++构建器XE6和Firebird执行请求后,如何获得请求的结果
- 获取命令行请求的结果并打开文件
- Libcurl请求没有结果