1

我只是 curlpp 的新手,但我看不出我的代码有什么问题,所以我希望有人能帮助我。

我在 C++ 中使用 curlpp 进行 Facebook Graph 查询。这意味着 Facebook 服务器将返回 Json 数据作为结果。

我的代码如下所示:

    #include <curlpp/cURLpp.hpp>
    #include <curlpp/Easy.hpp>
    #include <curlpp/Options.hpp>
    #include <curlpp/Exception.hpp>

    ...

    curlpp::Easy myRequest;
    bool error = false;
    QString result = "";

    try {
        // Setting the URL to the Facebook server with the query
        curlpp::options::Url myUrl(request->getURL().toStdString());
        // Creating stream for the result
        std::ostringstream os;
        curlpp::options::WriteStream ws(&os);

        // setting my opts: url and output stream
        myRequest.setOpt(myUrl);
        myRequest.setOpt(ws);

        // perform the request
        myRequest.perform();

        // stream the result into my stream
        os << myRequest;
        result = QString::fromStdString(os.str());
    } catch (curlpp::RuntimeError &e) {
        error = true;
        qWarning() << "Error in HttpRequest execution:" << e.what();
    } catch (curlpp::LogicError &e) {
        error = true;
        qWarning() << "Error in HttpRequest execution:" << e.what();
    } catch (...) {
        error = true;
        qWarning() << "Unknown error in HttpRequest execution.";
    }

我现在的问题是生成的流(以及我的结果 QString)确实包含 Facebook Graph 服务器发送的 Json 对象,但是两次。这意味着,直接两次相同的对象,一个接一个。这使得 Json 无效。

但这不可能是服务器提供的。当我使用 openssl 命令行工具检查它并自己发出 HTTP Get 请求时,这不是我得到的。

我的代码有什么问题?

最好的,迈克尔

4

0 回答 0