Tizen Native API  5.0

It manages HTTP request.

Required Header

#include <http.h>

Overview

It manages HTTP request message.

  • Set/Get URI, method
  • Make body for POST/PUT Method It supports other request options according to the HTTP protocol.

Functions

int http_transaction_request_set_method (http_transaction_h http_transaction, http_method_e method)
 Sets an HTTP method of the request header.
int http_transaction_request_get_method (http_transaction_h http_transaction, http_method_e *method)
 Gets the HTTP method from request header.
int http_transaction_request_set_version (http_transaction_h http_transaction, http_version_e version)
 Sets an HTTP version of the request header.
int http_transaction_request_get_version (http_transaction_h http_transaction, http_version_e *version)
 Gets the HTTP version from request header.
int http_transaction_request_set_uri (http_transaction_h http_transaction, const char *host_uri)
 Sets a URI of the request header.
int http_transaction_request_get_uri (http_transaction_h http_transaction, char **host_uri)
 Gets the URI.
int http_transaction_request_set_accept_encoding (http_transaction_h http_transaction, const char *encoding)
 Sets the Accept-Encoding header field of HTTP Request.
int http_transaction_request_get_accept_encoding (http_transaction_h http_transaction, char **encoding)
 Gets the Accept-Encoding header field of HTTP Request.
int http_transaction_request_set_cookie (http_transaction_h http_transaction, const char *cookie)
 Sets a cookie in the HTTP request.
int http_transaction_request_get_cookie (http_transaction_h http_transaction, char **cookie)
 Gets a cookie in the HTTP request.
int http_transaction_request_write_body (http_transaction_h http_transaction, const char *body)
 Writes the request message body.
int http_transaction_request_set_upload_file (http_transaction_h http_transaction, const char *file_path)
 Sets the file path for uploading a file.

Function Documentation

int http_transaction_request_get_accept_encoding ( http_transaction_h  http_transaction,
char **  encoding 
)

Gets the Accept-Encoding header field of HTTP Request.

Since :
3.0
Remarks:
The encoding should be freed using free().
Parameters:
[in]http_transactionThe HTTP transaction handle
[out]encodingThe encoding algorithms
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_get_cookie ( http_transaction_h  http_transaction,
char **  cookie 
)

Gets a cookie in the HTTP request.

Since :
3.0
Remarks:
The cookie should be freed using free().
Parameters:
[in]http_transactionThe HTTP transaction handle
[out]cookieThe cookie
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_get_method ( http_transaction_h  http_transaction,
http_method_e method 
)

Gets the HTTP method from request header.

Since :
3.0
Parameters:
[in]http_transactionThe HTTP transaction handle
[out]methodThe HTTP method
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_get_uri ( http_transaction_h  http_transaction,
char **  host_uri 
)

Gets the URI.

Since :
3.0
Remarks:
The host_uri should be freed using free().
Parameters:
[in]http_transactionThe HTTP transaction handle
[out]host_uriThe host URI
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_get_version ( http_transaction_h  http_transaction,
http_version_e version 
)

Gets the HTTP version from request header.

Gets the HTTP version.

Since :
3.0
Parameters:
[in]http_transactionThe HTTP transaction handle
[out]versionThe HTTP version
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_set_accept_encoding ( http_transaction_h  http_transaction,
const char *  encoding 
)

Sets the Accept-Encoding header field of HTTP Request.

The Accept-Encoding header enables automatic decompression of HTTP downloads.

Since :
3.0
Remarks:
If empty string is set, an Accept-Encoding header contains all supported built-in compressions.
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]encodingThe encoding algorithms (e.g. gzip, deflate)
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_set_cookie ( http_transaction_h  http_transaction,
const char *  cookie 
)

Sets a cookie in the HTTP request.

Since :
3.0
Remarks:
The format of string should be NME=CONTENTS (e.g. "name1=hello; name2=tizen;")
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]cookieThe cookie
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported

Sets an HTTP method of the request header.

Sets an HTTP method such as GET, POST, PUT and etc.

Since :
3.0
Remarks:
The default method is GET.
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]methodThe HTTP method
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_set_upload_file ( http_transaction_h  http_transaction,
const char *  file_path 
)

Sets the file path for uploading a file.

Since :
3.0
Remarks:
It is used with HTTP_METHOD_PUT.
http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.
http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]file_pathThe path for file
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
HTTP_ERROR_PERMISSION_DENIEDPermission denied
int http_transaction_request_set_uri ( http_transaction_h  http_transaction,
const char *  host_uri 
)

Sets a URI of the request header.

Sets a URI of the request header.

Since :
3.0
Remarks:
It should be used before http_transaction_submit().
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]host_uriThe URI to use in the request
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported

Sets an HTTP version of the request header.

Since :
3.0
Remarks:
The default version is HTTP 1.1.
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]versionThe HTTP version
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported
int http_transaction_request_write_body ( http_transaction_h  http_transaction,
const char *  body 
)

Writes the request message body.

This function writes the request message body in the internal queue.
The written queue for request body is uploaded after invoking http_transaction_submit().

Since :
3.0
Parameters:
[in]http_transactionThe HTTP transaction handle
[in]bodyThe message body data
Returns:
0 on success, otherwise negative error value
Return values:
HTTP_ERROR_NONESuccessful
HTTP_ERROR_INVALID_PARAMETERInvalid parameter
HTTP_ERROR_INVALID_OPERATIONInvalid operation
HTTP_ERROR_NOT_SUPPORTEDNot Supported