dsfml.network.http

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:

  • Http.Request
  • Http.Response
  • Http

$(PARA Http.Request builds the request that will be sent to the server. A request is made of:)

  • a method (what you want to do)
  • a target URI (usually the name of the web page or file)
  • one or more header fields (options that you can pass to the server)
  • an optional body (for POST requests)

$(PARA Http.Response parses the response from the web server and provides getters to read them. The response contains:)

  • a status code
  • header fields (that may be answers to the ones that you requested)
  • a body, which contains the contents of the requested resource

$(PARA $(U Http) provides a simple function, `sendRequest`, to send a Http.Request and return the corresponding Http.Response from the server.)

Members

Classes

Http
class Http

An HTTP client.

Examples

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 }

Meta