Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Curlpp przypisywanie wyniku do zmiennej

Ostatnio zmodyfikowano 2017-08-26 20:13
Autor Wiadomość
Bastian
Temat założony przez niniejszego użytkownika
Curlpp przypisywanie wyniku do zmiennej
» 2017-08-26 17:52:58
Czesc,

Pisze oto taką metode, która ma być parserem HTTP/HTTPS

C/C++
void KGrawler::parser( char * url )
{
   
    using namespace curlpp::options;
   
    try
    {
        // That's all that is needed to do cleanup of used resources (RAII style).
        curlpp::Cleanup myCleanup;
       
        // Our request to be sent.
        curlpp::Easy myRequest;
       
        // Set the URL.
        //myRequest.setOpt(curlpp::Options::Url(url));
        myRequest.setOpt < Url >( url );
       
        // Send request and get a result.
        // By default the result goes to standard output.
        myRequest.perform();
    }
    catch( curlpp::RuntimeError & e )
    {
        std::cout << e.what() << std::endl;
    }
   
    catch( curlpp::LogicError & e )
    {
        std::cout << e.what() << std::endl;
    }
}

W domyslnych ustawieniach curlpp::Easy:perform() wyrzyguje output na stdout. Aby zmienic do zachowanie z tego co czytam należy ustawić odpowiednio curlpp::OptionTrait<void *, CURLOPT_WRITEDATA>

Zatem probuje w taki sposób:

C/C++
void KGrawler::parser( char * url )
{
   
    using namespace curlpp::options;
   
    try
    {
        // That's all that is needed to do cleanup of used resources (RAII style).
        curlpp::Cleanup myCleanup;
       
        // Our request to be sent.
        curlpp::Easy myRequest;
       
        // Set the URL.
        //myRequest.setOpt(curlpp::Options::Url(url));
       
        //Redirect output to std::string object instead default std::cout              
        std::string oput;
        curlpp::OptionTrait < void *, CURLOPT_WRITEDATA > myData( oput );
        request.setOpt( myData );
       
        // Send request and get a result.
        // By default the result goes to standard output.
        myRequest.perform();
    }
    catch( curlpp::RuntimeError & e )
    {
        std::cout << e.what() << std::endl;
    }
   
    catch( curlpp::LogicError & e )
    {
        std::cout << e.what() << std::endl;
    }
}

Niestety słabo to rozumiem i dostaje błąd kompilacji:


/home/grzempek/git/KGrawler/src/KGrawler.cpp|66|error: no matching function for call to ‘curlpp::OptionTrait<void*, (CURLoption)10001u>::OptionTrait(std::string&)’|

Ktoś wie jak to poprawnie zrobić?

pzdr
P-164307
Kinexity
» 2017-08-26 18:21:06
To jest dział do pomocy z tutejszym kursem, a nie z BIBLIOTEKAMI.
P-164308
Bastian
Temat założony przez niniejszego użytkownika
» 2017-08-26 20:13:11
No tak.. przeraszam.
P-164309
« 1 »
  Strona 1 z 1