Http.h File Reference

#include <SFML/Config.h>
#include <SFML/Network/Types.h>

Go to the source code of this file.


Enumerations

enum  sfHttpMethod {
  sfHttpGet,
  sfHttpPost,
  sfHttpHead
}
 Enumerate the available HTTP methods for a request. More...
enum  sfHttpStatus {
  sfHttpOk = 200,
  sfHttpCreated = 201,
  sfHttpAccepted = 202,
  sfHttpNoContent = 204,
  sfHttpMultipleChoices = 300,
  sfHttpMovedPermanently = 301,
  sfHttpMovedTemporarily = 302,
  sfHttpNotModified = 304,
  sfHttpBadRequest = 400,
  sfHttpUnauthorized = 401,
  sfHttpForbidden = 403,
  sfHttpNotFound = 404,
  sfHttpInternalServerError = 500,
  sfHttpNotImplemented = 501,
  sfHttpBadGateway = 502,
  sfHttpServiceNotAvailable = 503,
  sfHttpInvalidResponse = 1000,
  sfHttpConnectionFailed = 1001
}
 Enumerate all the valid status codes returned in a HTTP response. More...

Functions

CSFML_API sfHttpRequestsfHttpRequest_Create ()
 Construct a new Http request.
CSFML_API void sfHttpRequest_Destroy (sfHttpRequest *HttpRequest)
 Destroy an existing Http request.
CSFML_API void sfHttpRequest_SetField (sfHttpRequest *HttpRequest, const char *Field, const char *Value)
 Set the value of a field; the field is added if it doesn't exist.
CSFML_API void sfHttpRequest_SetMethod (sfHttpRequest *HttpRequest, sfHttpMethod Method)
 Set the request method.
CSFML_API void sfHttpRequest_SetURI (sfHttpRequest *HttpRequest, const char *URI)
 Set the target URI of the request.
CSFML_API void sfHttpRequest_SetHttpVersion (sfHttpRequest *HttpRequest, unsigned int Major, unsigned int Minor)
 Set the HTTP version of the request.
CSFML_API void sfHttpRequest_SetBody (sfHttpRequest *HttpRequest, const char *Body)
 Set the body of the request.
CSFML_API void sfHttpResponse_Destroy (sfHttpResponse *HttpResponse)
 Destroy an existing Http response.
CSFML_API const char * sfHttpResponse_GetField (sfHttpResponse *HttpResponse, const char *Field)
 Get the value of a field; returns NULL if the field doesn't exist.
CSFML_API sfHttpStatus sfHttpResponse_GetStatus (sfHttpResponse *HttpResponse)
 Get the status of a response.
CSFML_API unsigned int sfHttpResponse_GetMajorVersion (sfHttpResponse *HttpResponse)
 Get the major HTTP version of a response.
CSFML_API unsigned int sfHttpResponse_GetMinorVersion (sfHttpResponse *HttpResponse)
 Get the minor HTTP version of a response.
CSFML_API const char * sfHttpResponse_GetBody (sfHttpResponse *HttpResponse)
 Get the body of the response.
CSFML_API sfHttpsfHttp_Create ()
 Construct a new Http object.
CSFML_API void sfHttp_Destroy (sfHttp *Http)
 Destroy an existing Http object.
CSFML_API void sfHttp_SetHost (sfHttp *Http, const char *Host, unsigned short Port)
 Set the target host of a Http server.
CSFML_API sfHttpResponsesfHttp_SendRequest (sfHttp *Http, sfHttpRequest *Request, float Timeout)
 Send a HTTP request and return the server's response.

Enumeration Type Documentation

Enumerate the available HTTP methods for a request.

Enumerator:
sfHttpGet  Request in get mode, standard method to retrieve a page.
sfHttpPost  Request in post mode, usually to send data to a page.
sfHttpHead  Request a page's header only.

Definition at line 38 of file Http.h.

Enumerate all the valid status codes returned in a HTTP response.

Enumerator:
sfHttpOk  Most common code returned when operation was successful.
sfHttpCreated  The resource has successfully been created.
sfHttpAccepted  The request has been accepted, but will be processed later by the server.
sfHttpNoContent  Sent when the server didn't send any data in return.
sfHttpMultipleChoices  The requested page can be accessed from several locations.
sfHttpMovedPermanently  The requested page has permanently moved to a new location.
sfHttpMovedTemporarily  The requested page has temporarily moved to a new location.
sfHttpNotModified  For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed.
sfHttpBadRequest  The server couldn't understand the request (syntax error).
sfHttpUnauthorized  The requested page needs an authentification to be accessed.
sfHttpForbidden  The requested page cannot be accessed at all, even with authentification.
sfHttpNotFound  The requested page doesn't exist.
sfHttpInternalServerError  The server encountered an unexpected error.
sfHttpNotImplemented  The server doesn't implement a requested feature.
sfHttpBadGateway  The gateway server has received an error from the source server.
sfHttpServiceNotAvailable  The server is temporarily unavailable (overloaded, in maintenance, ...).
sfHttpInvalidResponse  Response is not a valid HTTP one.
sfHttpConnectionFailed  Connection with server failed.

Definition at line 50 of file Http.h.


Function Documentation

CSFML_API sfHttp* sfHttp_Create (  ) 

Construct a new Http object.

Returns:
Pointer to the new Http

CSFML_API void sfHttp_Destroy ( sfHttp Http  ) 

Destroy an existing Http object.

Parameters:
Http : Http to destroy

CSFML_API sfHttpResponse* sfHttp_SendRequest ( sfHttp Http,
sfHttpRequest Request,
float  Timeout 
)

Send a HTTP request and return the server's response.

You must be connected to a host before sending requests. Any missing mandatory header field will be added with an appropriate value. Warning : this function waits for the server's response and may not return instantly; use a thread if you don't want to block your application.

Parameters:
Http : Http object
Request : Request to send
Timeout : Maximum time to wait (0 to use no timeout)
Returns:
Server's response, or NULL if request is invalid

CSFML_API void sfHttp_SetHost ( sfHttp Http,
const char *  Host,
unsigned short  Port 
)

Set the target host of a Http server.

Parameters:
Http : Http object
Host : Web server to connect to
Port : Port to use for connection (0 to use the standard port of the protocol used)

CSFML_API sfHttpRequest* sfHttpRequest_Create (  ) 

Construct a new Http request.

Returns:
Pointer to the new Http request

CSFML_API void sfHttpRequest_Destroy ( sfHttpRequest HttpRequest  ) 

Destroy an existing Http request.

Parameters:
HttpRequest : Http request to destroy

CSFML_API void sfHttpRequest_SetBody ( sfHttpRequest HttpRequest,
const char *  Body 
)

Set the body of the request.

This parameter is optional and makes sense only for POST requests. This parameter is empty by default

Parameters:
HttpRequest : Http request to modify
Body : Content of the request body

CSFML_API void sfHttpRequest_SetField ( sfHttpRequest HttpRequest,
const char *  Field,
const char *  Value 
)

Set the value of a field; the field is added if it doesn't exist.

Parameters:
HttpRequest : Http request to modify
Field : Name of the field to set (case-insensitive)
Value : Value of the field

CSFML_API void sfHttpRequest_SetHttpVersion ( sfHttpRequest HttpRequest,
unsigned int  Major,
unsigned int  Minor 
)

Set the HTTP version of the request.

This parameter is 1.0 by default

Parameters:
HttpRequest : Http request to modify
Major : Major version number
Minor : Minor version number

CSFML_API void sfHttpRequest_SetMethod ( sfHttpRequest HttpRequest,
sfHttpMethod  Method 
)

Set the request method.

This parameter is sfHttpGet by default

Parameters:
HttpRequest : Http request to modify
RequestMethod : Method to use for the request

CSFML_API void sfHttpRequest_SetURI ( sfHttpRequest HttpRequest,
const char *  URI 
)

Set the target URI of the request.

This parameter is "/" by default

Parameters:
HttpRequest : Http request to modify
URI : URI to request, local to the host

CSFML_API void sfHttpResponse_Destroy ( sfHttpResponse HttpResponse  ) 

Destroy an existing Http response.

Parameters:
HttpResponse : Http response to destroy

CSFML_API const char* sfHttpResponse_GetBody ( sfHttpResponse HttpResponse  ) 

Get the body of the response.

The body can contain :

  • the requested page (for GET requests)
  • a response from the server (for POST requests)
  • nothing (for HEAD requests)
  • an error message (in case of an error)

Parameters:
HttpResponse : Http response
Returns:
Body of the response (empty string if no body)

CSFML_API const char* sfHttpResponse_GetField ( sfHttpResponse HttpResponse,
const char *  Field 
)

Get the value of a field; returns NULL if the field doesn't exist.

Parameters:
HttpResponse : Http response
Field : Field to get
Returns:
Value of the field (NULL if it doesn't exist)

CSFML_API unsigned int sfHttpResponse_GetMajorVersion ( sfHttpResponse HttpResponse  ) 

Get the major HTTP version of a response.

Parameters:
HttpResponse : Http response
Returns:
HTTP major version of the response

CSFML_API unsigned int sfHttpResponse_GetMinorVersion ( sfHttpResponse HttpResponse  ) 

Get the minor HTTP version of a response.

Parameters:
HttpResponse : Http response
Returns:
HTTP minor version of the response

CSFML_API sfHttpStatus sfHttpResponse_GetStatus ( sfHttpResponse HttpResponse  ) 

Get the status of a response.

Parameters:
HttpResponse : Http response
Returns:
Status of the response