【问题标题】:I keep getting http/1.0 400 json rpc error with c++我不断收到 c++ 的 http/1.0 400 json rpc 错误
【发布时间】:2018-03-05 20:47:25
【问题描述】:
#include <stdio.h>
#include <iostream>
#include <thread>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <array>
#include <curl/curl.h>

size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(int argc, char * argv[])
{
curl_global_init(CURL_GLOBAL_ALL);

CURL* easyhandle = curl_easy_init();
std::string readBuffer;

curl_easy_setopt(easyhandle, CURLOPT_URL, "http://192.168.1.79:8080");
curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(easyhandle, CURLOPT_POST, 1);
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS,"{ \"jsonrpc\": \"2.0\", \"method\": \"get\", \"params\": [\"Frozen\"], \"id\": 3}");
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &readBuffer);

curl_easy_perform(easyhandle);

std::cout << readBuffer << std::endl;
//std::cout << "{ \"jsonrpc\": \"2.0\", \"method\": \"getTitles\", \"params\": [clea], \"id\": 3}" << std::endl;

return 0;
}

这是我的 curl 命令的代码。我看到请求通过我的服务器,但它一直说 rpc 错误。我认为这是我格式化我的 json 的方式。基本上在我的电脑上,如果我在终端中运行这个 curl 命令,它就可以工作。但是,在 c++ 中运行它是行不通的。

【问题讨论】:

    标签: c++ json curl


    【解决方案1】:

    原来“冰雪奇缘”不在图书馆。将其添加到服务器上后,它就可以工作了。

    【讨论】:

      猜你喜欢
      • 2019-04-20
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2023-03-22
      • 2022-11-26
      • 2021-12-14
      • 2015-11-08
      • 1970-01-01
      相关资源
      最近更新 更多