An HTTP client.
1 // Create a new HTTP client 2 auto http = new Http(); 3 4 // We'll work on http://www.sfml-dev.org 5 http.setHost("http://www.sfml-dev.org"); 6 7 // Prepare a request to get the 'features.php' page 8 auto request = new Http.Request("features.php"); 9 10 // Send the request 11 auto response = http.sendRequest(request); 12 13 // Check the status code and display the result 14 auto status = response.getStatus(); 15 if (status == Http.Response.Status.Ok) 16 { 17 writeln(response.getBody()); 18 } 19 else 20 { 21 writeln("Error ", status); 22 }
The Http class is a very simple HTTP client that allows you to communicate with a web server. You can retrieve web pages, send data to an interactive resource, download a remote file, etc. The HTTPS protocol is not supported.
The HTTP client is split into 3 classes:
$(PARA Http.Request builds the request that will be sent to the server. A request is made of:)
$(PARA Http.Response parses the response from the web server and provides getters to read them. The response contains:)
$(PARA $(U Http) provides a simple function, `sendRequest`, to send a Http.Request and return the corresponding Http.Response from the server.)