diff options
Diffstat (limited to 'tests/libcurlpp/test1.cpp')
-rw-r--r-- | tests/libcurlpp/test1.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/libcurlpp/test1.cpp b/tests/libcurlpp/test1.cpp new file mode 100644 index 0000000..d10ef02 --- /dev/null +++ b/tests/libcurlpp/test1.cpp @@ -0,0 +1,66 @@ +#include <curlpp/cURLpp.hpp> +#include <curlpp/Easy.hpp> +#include <curlpp/Options.hpp> +#include <curlpp/Infos.hpp> +#include <curlpp/Types.hpp> + +#include <iostream> +#include <sys/types.h> +#include <cassert> +#include <cstring> +#include <cstdlib> + +using namespace std; +using namespace cURLpp; + +static char *c = NULL; +static size_t c_size = 0; + +static size_t f( char *ptr, size_t s, size_t n ) { + size_t size = s * n; + + if( c_size == 0 ) + c = (char *)malloc( size + 1 ); + else + c = (char *)realloc( c, c_size + size + 1 ); + + assert( c != NULL ); + + memcpy( &c[c_size], ptr, size ); + c_size += size; + c[c_size] = '\0'; + + return size; +} + +int main( int argc, char *argv[] ) { + char *url; + Easy curl; + + if( argc != 2 ) { + cerr << "usage: test1 <url>" << endl; + return EXIT_FAILURE; + } + url = argv[1]; + + curl.setOpt( Options::Url( url ) ); + //curl.setOpt( Options::Header( true ) ); + //curl.setOpt( Options::Verbose( true ) ); + + Types::WriteFunctionFunctor functor( f ); + Options::WriteFunction *wf = new Options::WriteFunction( f ); + curl.setOpt( wf ); + + curl.perform( ); + + cout << cURLpp::Infos::ResponseCode::get( curl ) << endl + << c_size << " " + << url << endl; + + cout << c << endl; + + assert( c != NULL ); + free( c ); + + return EXIT_SUCCESS; +} |