[curl] Pobieranie danych ze skryptu php
Ostatnio zmodyfikowano 2014-11-03 23:13
Hipochondryk Temat założony przez niniejszego użytkownika |
[curl] Pobieranie danych ze skryptu php » 2014-11-03 21:45:17 Witam mam taki o to kod : #include <stdio.h> #include <curl/curl.h> #include <iostream> #include <string>
int main( void ) { CURL * curl; CURLcode res; curl_global_init( CURL_GLOBAL_ALL ); curl = curl_easy_init(); std::string temp; if( curl ) { curl_easy_setopt( curl, CURLOPT_URL, "http://NazwaStrony.pl/skrypt.php" ); curl_easy_setopt( curl, CURLOPT_POSTFIELDS, "login=111111&pass=UdaloSie1&repass=UdaloSie1" ); res = curl_easy_perform( curl ); if( res != CURLE_OK ) fprintf( stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror( res ) ); curl_easy_cleanup( curl ); } curl_global_cleanup(); std::cin.get(); std::cin.get(); return 0; }
Ten kod wykonuje skrypt. Skrypt potem wyświetla informację za pomocą funkcji echo. Ta informacja jest widoczna w konsoli. Chciałbym ją teraz przechycić do zmiennej typu string. Czy mógłbym prosić o pomoc jak to zrobić ? |
|
Hipochondryk Temat założony przez niniejszego użytkownika |
» 2014-11-03 23:13:59 #include <stdio.h> #include <curl/curl.h> #include <iostream> #include <string>
size_t writefunc( char * data, size_t size, size_t nmemb, string * s ) { if( s != NULL ) { s->append( data, size * nmemb ); } return size * nmemb; }
int main( void ) { CURL * curl; CURLcode res; curl_global_init( CURL_GLOBAL_ALL ); curl = curl_easy_init(); std::string temp; if( curl ) { curl_easy_setopt( curl, CURLOPT_URL, "http://NazwaStrony.pl/skrypt.php" ); curl_easy_setopt( curl, CURLOPT_POSTFIELDS, "login=111111&pass=UdaloSie1&repass=UdaloSie1" ); curl_easy_setopt( curl, CURLOPT_WRITEDATA, & temp ); res = curl_easy_perform( curl ); if( res != CURLE_OK ) fprintf( stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror( res ) ); curl_easy_cleanup( curl ); } curl_global_cleanup(); std::cin.get(); std::cin.get(); return 0; }
Trochę poszperałem, trochę popytałem i napisałem funkcję która do stringu temp wrzuca mi te info które mnie interesowało. |
|
« 1 » |