pixelmaster |
» 2009-03-24 20:53:15 Znalazłem coś takiego http://www.luckyspin.org/?p=28 ale nie sprawdzałem czy działa. Wkleje kod z tamtąd, aby mój post wyglądał pokaźniej :E
#include <string> #include <iostream> #include "curl/curl.h"
using namespace std;
static char errorBuffer[ CURL_ERROR_SIZE ];
static string buffer;
static int writer( char * data, size_t size, size_t nmemb, std::string * buffer ) { int result = 0; if( buffer != NULL ) { buffer->append( data, size * nmemb ); result = size * nmemb; } return result; }
void usage() { cout < < "curltest: \n" << endl; cout << " Usage: curltest url\n" << endl; }
int main( int argc, char * argv[] ) { if( argc > 1 ) { string url( argv[ 1 ] ); cout < < "Retrieving " << url << endl; CURL * curl; CURLcode result; curl = curl_easy_init(); if( curl ) { curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, errorBuffer ); curl_easy_setopt( curl, CURLOPT_URL, argv[ 1 ] ); curl_easy_setopt( curl, CURLOPT_HEADER, 0 ); curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 1 ); curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, writer ); curl_easy_setopt( curl, CURLOPT_WRITEDATA, & buffer ); result = curl_easy_perform( curl ); curl_easy_cleanup( curl ); if( result == CURLE_OK ) { cout << buffer << "\n"; exit( 0 ); } else { cout << "Error: [" << result << "] - " << errorBuffer; exit( - 1 ); } } } }
|
|
pekfos Temat założony przez niniejszego użytkownika |
» 2009-03-25 12:04:49 przetłumaczę sobie komentarze to może coś zrozumiem.. #include <string> #include <iostream> #include "curl/curl.h"
using namespace std;
static char errorBuffer[ CURL_ERROR_SIZE ];
static string buffer;
static int writer( char * data, size_t size, size_t nmemb, std::string * buffer ) { int result = 0; if( buffer != NULL ) { buffer->append( data, size * nmemb ); result = size * nmemb; } return result; }
void usage() { cout < < "curltest: \n" << endl; cout << " Usage: curltest url\n" << endl; }
int main( int argc, char * argv[] ) { if( argc > 1 ) { string url( argv[ 1 ] ); cout < < "Retrieving " << url << endl; CURL * curl; CURLcode result; curl = curl_easy_init(); if( curl ) { curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, errorBuffer ); curl_easy_setopt( curl, CURLOPT_URL, argv[ 1 ] ); curl_easy_setopt( curl, CURLOPT_HEADER, 0 ); curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 1 ); curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, writer ); curl_easy_setopt( curl, CURLOPT_WRITEDATA, & buffer ); result = curl_easy_perform( curl ); curl_easy_cleanup( curl ); if( result == CURLE_OK ) { cout << buffer << "\n"; exit( 0 ); } else { cout << "Error: [" << result << "] - " << errorBuffer; exit( - 1 ); } } } } tego curl_easy_setopt() nie rozumiem.. wiem tylko że pierwszy argument to wskaźnik do objektu curl'a |
|
DejaVu |
» 2009-03-25 12:34:48 curl_easy_setopt()
Innymi słowy: Curl Easy Set Option Parametr 1: wskaźnik do zainicjowanej struktury Parametr 2: opcja, którą chcemy ustawić Parametr 3: nowa wartość dla opcji
|
|
pekfos Temat założony przez niniejszego użytkownika |
» 2009-03-25 12:39:04 jakie opcje trzeba ustawić?
//edit:
CURLOPT_URL domyślam sie że adres strony internetowej CURLOPT_ERRORBUFFER bufor błędów
tylko jeszcze nie rozumiem dwóch opcji: CURLOPT_HEADER i CURLOPT_FOLLOWLOCATION.
//edit2:
CURLOPT_WRITEDATA wskaźnik do bufora do którego chyba będą zapisywane dane CURLOPT_WRITEFUNCTION wskaźnik do jakiejś funkcji (jeszcze tego nie rozpracowałem:D)
//edit3:
hmm.. nie rozumiem co robi fukcja writer() w tym przykładzie
//edit4:
czy na repo jest paczka curl'a bo coś niewiem którą trzeba pobrać (mnóstwo tego :D) |
|
DejaVu |
» 2009-03-25 18:30:22 Jeśli używasz Dev-C++, skorzystaj z aktualizacji - pójdzie dużo łatwiej i niemalże bezboleśnie. |
|
pekfos Temat założony przez niniejszego użytkownika |
» 2009-03-25 18:54:02 7.14.0_ssl czy 7.14.0_nossl?? |
|
pekfos Temat założony przez niniejszego użytkownika |
» 2009-03-28 09:08:49 hm.. są dwie wersje curl'a i nie wiem którą wybrać i nie wiem czym się różnią. 7.14.0_ssl i 7.14.0_nossl którą wybrać? |
|
DejaVu |
» 2009-03-28 10:19:22 Jedna obsługuje SSL druga nie. |
|
1 « 2 » 3 |