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 (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 (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 reponse. | |
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 (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.
◆ sfHttpStatus
enum sfHttpStatus |
Enumerate all the valid status codes for a response.
Function Documentation
◆ sfHttp_create()
sfHttp * sfHttp_create | ( | void | ) |
Create a new Http object.
- Returns
- A new sfHttp object
◆ sfHttp_destroy()
void sfHttp_destroy | ( | 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 defaut 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 | ( | 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 availale 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 | ( | 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 reponse.
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