1#include <cstdlib> 2#include <cstring> 3#include <cstdio> 4#include <iostream> 5 6#include <KernelKit.h> 7#include <NetworkKit.h> 8 9using std::cout; 10using std::endl; 11 12int 13main(int, char**) 14{ 15 BUrl yahoo("http://www.yahoo.fr"); 16 BUrlContext c; 17 BUrlRequest t(yahoo); 18 19 t.SetContext(&c); 20 21 if (!t.InitCheck()) { 22 cout << "URL request failed to initialize" << endl; 23 return EXIT_FAILURE; 24 } 25 26 if (t.Perform() != B_OK) { 27 cout << "Error while performing request!" << endl; 28 return EXIT_FAILURE; 29 } 30 31 // Do nothing while the request is not finished 32 while (t.IsRunning()) { 33 cout << std::flush; 34 snooze(10000); 35 } 36 37 // Print the result 38 cout << "Request result : " << t.Result().StatusCode() << " (" << t.Result().StatusText() << ")" << endl; 39 //cout << " * " << c.GetCookieJar().CountCookies() << " cookies in context after request" << endl; 40 cout << " * " << t.Result().Headers().CountHeaders() << " headers received" << endl; 41 cout << " * " << t.Result().RawData().Position() << " bytes of raw data:" << endl; 42 cout << t.Result() << endl; 43 cout << "End of request" << endl << endl; 44 45 // Flat view of the cookie jar : 46 cout << "cookie.txt :" << endl; 47 48 ssize_t flatSize = c.GetCookieJar().FlattenedSize(); 49 char *flatCookieJar = new char[flatSize]; 50 51 c.GetCookieJar().Flatten(flatCookieJar, flatSize); 52 53 cout << flatCookieJar << endl << endl; 54 55 return EXIT_SUCCESS; 56} 57