CSFML - C binding of the Simple and Fast Multimedia Library

CSFML 3.0.0

- Main Page
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
Enumerations | Functions
Http.h File Reference
`#include <CSFML/Network/Export.h>`
`#include <CSFML/Network/Types.h>`
`#include <CSFML/System/Time.h>`

Go to the source code of this file.

## Enumerations
enum | sfHttpMethod { sfHttpGet , sfHttpPost , sfHttpHead , sfHttpPut , sfHttpDelete }
| Enumerate the available HTTP methods for a request. More...
enum | sfHttpStatus { sfHttpOk = 200 , sfHttpCreated = 201 , sfHttpAccepted = 202 , sfHttpNoContent = 204 , sfHttpResetContent = 205 , sfHttpPartialContent = 206 , sfHttpMultipleChoices = 300 , sfHttpMovedPermanently = 301 , sfHttpMovedTemporarily = 302 , sfHttpNotModified = 304 , sfHttpBadRequest = 400 , sfHttpUnauthorized = 401 , sfHttpForbidden = 403 , sfHttpNotFound = 404 , sfHttpRangeNotSatisfiable = 407 , sfHttpInternalServerError = 500 , sfHttpNotImplemented = 501 , sfHttpBadGateway = 502 , sfHttpServiceNotAvailable = 503 , sfHttpGatewayTimeout = 504 , sfHttpVersionNotSupported = 505 , sfHttpInvalidResponse = 1000 , sfHttpConnectionFailed = 1001 }
| Enumerate all the valid status codes for a response. More...

## Functions
sfHttpRequest * | sfHttpRequest_create (void)
| Create a new HTTP request.
void | sfHttpRequest_destroy (const sfHttpRequest *httpRequest)
| Destroy a HTTP request.
void | sfHttpRequest_setField (sfHttpRequest *httpRequest, const char *field, const char *value)
| Set the value of a header field of a HTTP request.
void | sfHttpRequest_setMethod (sfHttpRequest *httpRequest, sfHttpMethod method)
| Set a HTTP request method.
void | sfHttpRequest_setUri (sfHttpRequest *httpRequest, const char *uri)
| Set a HTTP request URI.
void | sfHttpRequest_setHttpVersion (sfHttpRequest *httpRequest, unsigned int major, unsigned int minor)
| Set the HTTP version of a HTTP request.
void | sfHttpRequest_setBody (sfHttpRequest *httpRequest, const char *body)
| Set the body of a HTTP request.
void | sfHttpResponse_destroy (const sfHttpResponse *httpResponse)
| Destroy a HTTP response.
const char * | sfHttpResponse_getField (const sfHttpResponse *httpResponse, const char *field)
| Get the value of a field of a HTTP response.
sfHttpStatus | sfHttpResponse_getStatus (const sfHttpResponse *httpResponse)
| Get the status code of a HTTP response.
unsigned int | sfHttpResponse_getMajorVersion (const sfHttpResponse *httpResponse)
| Get the major HTTP version number of a HTTP response.
unsigned int | sfHttpResponse_getMinorVersion (const sfHttpResponse *httpResponse)
| Get the minor HTTP version number of a HTTP response.
const char * | sfHttpResponse_getBody (const sfHttpResponse *httpResponse)
| Get the body of a HTTP response.
sfHttp * | sfHttp_create (void)
| Create a new Http object.
void | sfHttp_destroy (const sfHttp *http)
| Destroy a Http object.
void | sfHttp_setHost (sfHttp *http, const char *host, unsigned short port)
| Set the target host of a HTTP object.
sfHttpResponse * | sfHttp_sendRequest (sfHttp *http, const sfHttpRequest *request, sfTime timeout)
| Send a HTTP request and return the server's response.

## Enumeration Type Documentation

## ◆ sfHttpMethod

enum sfHttpMethod

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.
sfHttpPut | Request in put mode, useful for a REST API.
sfHttpDelete | Request in delete mode, useful for a REST API.

Definition at line 40 of file Http.h.

## ◆ sfHttpStatus

enum sfHttpStatus

Enumerate all the valid status codes for a 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.
sfHttpResetContent | The server informs the client that it should clear the view (form) that caused the request to be sent.
sfHttpPartialContent | The server has sent a part of the resource, as a response to a partial GET request.
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 conditional 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 authentication to be accessed.
sfHttpForbidden | The requested page cannot be accessed at all, even with authentication.
sfHttpNotFound | The requested page doesn't exist.
sfHttpRangeNotSatisfiable | The server can't satisfy the partial GET request (with a "Range" header field)
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, ...)
sfHttpGatewayTimeout | The gateway server couldn't receive a response from the source server.
sfHttpVersionNotSupported | The server doesn't support the requested HTTP version.
sfHttpInvalidResponse | Response is not a valid HTTP one.
sfHttpConnectionFailed | Connection with server failed.

Definition at line 54 of file Http.h.

## Function Documentation

## ◆ sfHttp_create()

sfHttp * sfHttp_create | ( | void |  | ) |

Create a new Http object.

Returns
  A new sfHttp object

## ◆ sfHttp_destroy()

void sfHttp_destroy | ( | const sfHttp * | http | ) |

Destroy a Http object.

Parameters

  http | Http object to destroy

## ◆ sfHttp_sendRequest()

sfHttpResponse * sfHttp_sendRequest | ( | sfHttp * | http,
|  | const sfHttpRequest * | request,
|  | sfTime | timeout )

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

You must have a valid host before sending a request (see sfHttp_setHost). Any missing mandatory header field in the request 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, or use a timeout to limit the time to wait. A value of 0 means that the client will use the system default timeout (which is usually pretty long).

Parameters

  http | Http object
  request | Request to send
  timeout | Maximum time to wait

Returns
  Server's response

## ◆ sfHttp_setHost()

void sfHttp_setHost | ( | sfHttp * | http,
|  | const char * | host,
|  | unsigned short | port )

Set the target host of a HTTP object.

This function just stores the host address and port, it doesn't actually connect to it until you send a request. If the port is 0, it means that the HTTP client will use the right port according to the protocol used (80 for HTTP, 443 for HTTPS). You should leave it like this unless you really need a port other than the standard one, or use an unknown protocol.

Parameters

  http | Http object
  host | Web server to connect to
  port | Port to use for connection

## ◆ sfHttpRequest_create()

sfHttpRequest * sfHttpRequest_create | ( | void |  | ) |

Create a new HTTP request.

Returns
  A new sfHttpRequest object

## ◆ sfHttpRequest_destroy()

void sfHttpRequest_destroy | ( | const sfHttpRequest * | httpRequest | ) |

Destroy a HTTP request.

Parameters

  httpRequest | HTTP request to destroy

## ◆ sfHttpRequest_setBody()

void sfHttpRequest_setBody | ( | sfHttpRequest * | httpRequest,
|  | const char * | body )

Set the body of a HTTP request.

The body of a request is optional and only makes sense for POST requests. It is ignored for all other methods. The body is empty by default.

Parameters

  httpRequest | HTTP request
  body | Content of the body

## ◆ sfHttpRequest_setField()

void sfHttpRequest_setField | ( | sfHttpRequest * | httpRequest,
|  | const char * | field,
|  | const char * | value )

Set the value of a header field of a HTTP request.

The field is created if it doesn't exist. The name of the field is case insensitive. By default, a request doesn't contain any field (but the mandatory fields are added later by the HTTP client when sending the request).

Parameters

  httpRequest | HTTP request
  field | Name of the field to set
  value | Value of the field

## ◆ sfHttpRequest_setHttpVersion()

void sfHttpRequest_setHttpVersion | ( | sfHttpRequest * | httpRequest,
|  | unsigned int | major,
|  | unsigned int | minor )

Set the HTTP version of a HTTP request.

The HTTP version is 1.0 by default.

Parameters

  httpRequest | HTTP request
  major | Major HTTP version number
  minor | Minor HTTP version number

## ◆ sfHttpRequest_setMethod()

void sfHttpRequest_setMethod | ( | sfHttpRequest * | httpRequest,
|  | sfHttpMethod | method )

Set a HTTP request method.

See the sfHttpMethod enumeration for a complete list of all the available methods. The method is sfHttpGet by default.

Parameters

  httpRequest | HTTP request
  method | Method to use for the request

## ◆ sfHttpRequest_setUri()

void sfHttpRequest_setUri | ( | sfHttpRequest * | httpRequest,
|  | const char * | uri )

Set a HTTP request URI.

The URI is the resource (usually a web page or a file) that you want to get or post. The URI is "/" (the root page) by default.

Parameters

  httpRequest | HTTP request
  uri | URI to request, relative to the host

## ◆ sfHttpResponse_destroy()

void sfHttpResponse_destroy | ( | const sfHttpResponse * | httpResponse | ) |

Destroy a HTTP response.

Parameters

  httpResponse | HTTP response to destroy

## ◆ sfHttpResponse_getBody()

const char * sfHttpResponse_getBody | ( | const sfHttpResponse * | httpResponse | ) |

Get the body of a HTTP response.

The body of a response may 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
  The response body

## ◆ sfHttpResponse_getField()

const char * sfHttpResponse_getField | ( | const sfHttpResponse * | httpResponse,
|  | const char * | field )

Get the value of a field of a HTTP response.

If the field field is not found in the response header, the empty string is returned. This function uses case-insensitive comparisons.

Parameters

  httpResponse | HTTP response
  field | Name of the field to get

Returns
  Value of the field, or empty string if not found

## ◆ sfHttpResponse_getMajorVersion()

unsigned int sfHttpResponse_getMajorVersion | ( | const sfHttpResponse * | httpResponse | ) |

Get the major HTTP version number of a HTTP response.

Parameters

  httpResponse | HTTP response

Returns
  Major HTTP version number

## ◆ sfHttpResponse_getMinorVersion()

unsigned int sfHttpResponse_getMinorVersion | ( | const sfHttpResponse * | httpResponse | ) |

Get the minor HTTP version number of a HTTP response.

Parameters

  httpResponse | HTTP response

Returns
  Minor HTTP version number

## ◆ sfHttpResponse_getStatus()

sfHttpStatus sfHttpResponse_getStatus | ( | const sfHttpResponse * | httpResponse | ) |

Get the status code of a HTTP response.

The status code should be the first thing to be checked after receiving a response, it defines whether it is a success, a failure or anything else (see the sfHttpStatus enumeration).

Parameters

  httpResponse | HTTP response

Returns
  Status code of the response