How to get response files using curlpp?

how can i get response files from curlpp request?

I want to save a PHP session from a GET HTTP request. This is my current code:

void Grooveshark::Connection::processPHPCookie()
{
    std::ostringstream buffer;

    gsDebug("Processing PHP cookie...");

    try {
        request.setOpt<cURLpp::Options::Url>("http://listen.grooveshark.com");
        request.setOpt<cURLpp::Options::WriteStream>(&buffer);
        request.perform();

        // Get the PHP Session cookie here..

    } catch (cURLpp::LogicError& exception) {
        gsError(exception.what());
    } catch (cURLpp::RuntimeError& exception) {
        gsError(exception.what());
    }

    gsDebug("Processing complete...");
}

requestis an instance cURLpp::Easy. If you need more information, you can find my source code here.

Thanks in advance.

+3
source share
2 answers

https://bitbucket.org/moriarty/curlpp/src/ac658073c87a/examples/example07.cpp

This example seems to have what you want. In particular, this code:

std::cout << "\nCookies from cookie engine:" << std::endl;
std::list<std::string> cookies;
curlpp::infos::CookieList::get(exEasy, cookies);
int i = 1;
for (std::list<std::string>::const_iterator it = cookies.begin(); it != cookies.end(); ++it, i++)
{
    std::cout << "[" << i << "]: " << MakeCookie(*it) << std::endl;
}

Note that MakeCookie returns a structure called MyCookie in this example, so you will also need:

struct MyCookie
{
        std::string name;
        std::string value;
        std::string domain;
        std::string path;
        time_t expires;
        bool tail;
        bool secure;
};

MyCookie
MakeCookie(const std::string &str_cookie)
{
        std::vector<std::string> vC = splitCookieStr(str_cookie);
        MyCookie cook;

        cook.domain = vC[0];
        cook.tail = vC[1] == "TRUE";
        cook.path = vC[2];
        cook.secure = vC[3] == "TRUE";
        cook.expires = StrToInt(vC[4]);
        cook.name = vC[5];
        cook.value = vC[6];

        return cook;
}
0
source

: https://github.com/datacratic/curlpp/blob/master/examples/example07.cpp.

, - cookie, cookie.

exEasy.setOpt(new curlpp::options::CookieList("")), cookie ( - , ).

0

Source: https://habr.com/ru/post/1778553/


All Articles