mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 18:16:31 +03:00
Added support for AsyncRequests in cHttp.
Added cThreadLocal and tThreadLocalPtr ( needed for the async requests ).
This commit is contained in:
@@ -1,28 +1,44 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
/// Entry point of application
|
||||
EE_MAIN_FUNC int main (int argc, char * argv [])
|
||||
{
|
||||
// Create a new HTTP client
|
||||
cHttp http;
|
||||
void AsyncRequestCallback( const cHttp& http, cHttp::Request& request, cHttp::Response& response ) {
|
||||
std::cout << "Got response from request: " << http.GetHostName() << request.GetUri() << std::endl;
|
||||
|
||||
// We'll work on http://www.wikipedia.org
|
||||
http.SetHost("http://www.wikipedia.org");
|
||||
|
||||
// Prepare a request to get the '/' page
|
||||
cHttp::Request request("/");
|
||||
|
||||
// Send the request
|
||||
cHttp::Response response = http.SendRequest(request);
|
||||
|
||||
// Check the status code and display the result
|
||||
cHttp::Response::Status status = response.GetStatus();
|
||||
|
||||
if ( status == cHttp::Response::Ok ) {
|
||||
if ( response.GetStatus() == cHttp::Response::Ok ) {
|
||||
std::cout << response.GetBody() << std::endl;
|
||||
} else {
|
||||
std::cout << "Error " << status << std::endl;
|
||||
std::cout << "Error " << response.GetStatus() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
{
|
||||
// Create a new HTTP client
|
||||
cHttp http;
|
||||
|
||||
// We'll work on http://en.wikipedia.org
|
||||
http.SetHost("http://en.wikipedia.org");
|
||||
|
||||
// Prepare a request to get the '/' page
|
||||
cHttp::Request request("/wiki/Main_Page");
|
||||
|
||||
// Send the request
|
||||
cHttp::Response response = http.SendRequest(request);
|
||||
|
||||
// Check the status code and display the result
|
||||
cHttp::Response::Status status = response.GetStatus();
|
||||
|
||||
if ( status == cHttp::Response::Ok ) {
|
||||
std::cout << response.GetBody() << std::endl;
|
||||
} else {
|
||||
std::cout << "Error " << status << std::endl;
|
||||
}
|
||||
|
||||
cHttp::Request asyncRequest( "/wiki/" + Version::GetCodename() );
|
||||
|
||||
http.SendAsyncRequest( cb::Make3( AsyncRequestCallback ), asyncRequest, Seconds( 5 ) );
|
||||
}
|
||||
|
||||
MemoryManager::ShowResults();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user