duanfu6160 2015-08-08 10:40
浏览 48

C ++ Elasticsearch错误NullPointerException [null]

i try to update data on a elasticsearch server. I use C++ and libcurl to update the data. When i send the curl request i get the following response: {{"error":"NullPointerException[null]", "status":500}}

I have try the same curl request in PHP and it works. Here is my code:

C++:

    CURL *curl;
    CURLcode res;
    std::string readBuffer;



    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    if(curl){std::cout << "curl init" << std::endl;}
    curl_easy_setopt(curl, CURLOPT_URL, "IP:9200/test/player/2/_update");
    curl_easy_setopt(curl, CURLOPT_PORT, 9200);
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, '{ "doc": { "x": 757575 }}');

    std::cout << "performing" << std::endl;
    res = curl_easy_perform(curl);
    if(res != CURLE_OK) {
        ChatPacket(CHAT_TYPE_INFO,"curl_easy_perform() failed: %s
", curl_easy_strerror(res));
    }

    std::cout << readBuffer << std::endl;

    curl_easy_cleanup(curl);
    curl_global_cleanup();

PHP:

        $ch = curl_init();
        $method = "POST";
        $url = "IP:9200/test/player/2/_update";

        $query = 
        '{
         "doc": {
              "x": 757575
          }
         }';


        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PORT, 9200);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);

        $result = curl_exec($ch);
        curl_close($ch);

        echo $result;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥15 MCNP里如何定义多个源?
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏