mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 10:06:35 +03:00
Network module refactored.
--HG-- branch : dev
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
void AsyncRequestCallback( const Http& http, Http::Request& request, Http::Response& response ) {
|
||||
std::cout << "Got response from request: " << http.GetHostName() << request.GetUri() << std::endl;
|
||||
std::cout << "Got response from request: " << http.getHostName() << request.getUri() << std::endl;
|
||||
|
||||
if ( response.GetStatus() == Http::Response::Ok ) {
|
||||
std::cout << response.GetBody() << std::endl;
|
||||
if ( response.getStatus() == Http::Response::Ok ) {
|
||||
std::cout << response.getBody() << std::endl;
|
||||
} else {
|
||||
std::cout << "Error " << response.GetStatus() << std::endl;
|
||||
std::cout << "Error " << response.getStatus() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,38 +18,38 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
|
||||
if ( argc < 2 ) {
|
||||
// We'll work on http://en.wikipedia.org
|
||||
if ( SSLSocket::IsSupported() ) {
|
||||
http.SetHost("https://en.wikipedia.org");
|
||||
if ( SSLSocket::isSupported() ) {
|
||||
http.setHost("https://en.wikipedia.org");
|
||||
} else {
|
||||
http.SetHost("http://en.wikipedia.org");
|
||||
http.setHost("http://en.wikipedia.org");
|
||||
}
|
||||
|
||||
// Prepare a request to get the wikipedia main page
|
||||
request.SetUri("/wiki/Main_Page");
|
||||
request.setUri("/wiki/Main_Page");
|
||||
|
||||
// Creates an async http request
|
||||
Http::Request asyncRequest( "/wiki/" + Version::getCodename() );
|
||||
|
||||
http.SendAsyncRequest( cb::Make3( AsyncRequestCallback ), asyncRequest, Seconds( 5 ) );
|
||||
http.sendAsyncRequest( cb::Make3( AsyncRequestCallback ), asyncRequest, Seconds( 5 ) );
|
||||
} else {
|
||||
// If the user provided the URI, creates an instance of URI to parse it.
|
||||
URI uri( argv[1] );
|
||||
|
||||
// Set the host and port from the URI
|
||||
http.SetHost( uri.GetHost(), uri.GetPort() );
|
||||
http.setHost( uri.getHost(), uri.getPort() );
|
||||
|
||||
// Set the path and query parts for the request
|
||||
request.SetUri( uri.GetPathAndQuery() );
|
||||
request.setUri( uri.getPathAndQuery() );
|
||||
}
|
||||
|
||||
// Send the request
|
||||
Http::Response response = http.SendRequest(request);
|
||||
Http::Response response = http.sendRequest(request);
|
||||
|
||||
// Check the status code and display the result
|
||||
Http::Response::Status status = response.GetStatus();
|
||||
Http::Response::Status status = response.getStatus();
|
||||
|
||||
if ( status == Http::Response::Ok ) {
|
||||
std::cout << response.GetBody() << std::endl;
|
||||
std::cout << response.getBody() << std::endl;
|
||||
} else {
|
||||
std::cout << "Error " << status << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user