1

I'm just new to curlpp but I can't see what's wrong here with my code, so I hope someone can help me out.

I'm using curlpp in C++ to make Facebook Graph queries. That means the Facebook server will return Json data as result.

My code looks as follows:

    #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.";
    }

My problem now is that the resulting stream (and thus my result QString) do contain the Json object sent by the Facebook Graph server, but twice. That means, directly two times the same object, one after the other. And that makes it invalid Json.

But that can not be what the server delivers. And it's not what I get when I do check it with the openssl command line tool and make a HTTP Get request on my own.

What's wrong with my code?

Best, Michael

michael.k
  • 168
  • 9

0 Answers0