Cocos2d-x  4.0.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
HttpClient Class Reference

Singleton that handles asynchronous http requests. More...

Public Member Functions

void enableCookies (const char *cookieFile)
 Enable cookie support.
 
const std::string & getCookieFilename ()
 Get the cookie filename.
 
void setSSLVerification (const std::string &caFile)
 Set root certificate path for SSL verification.
 
const std::string & getSSLVerification ()
 Get the ssl CA filename.
 
void send (HttpRequest *request)
 Add a get request to task queue.
 
void sendImmediate (HttpRequest *request)
 Immediate send a request.
 
void setTimeoutForConnect (int value)
 Set the timeout value for connecting.
 
int getTimeoutForConnect ()
 Get the timeout value for connecting.
 
void setTimeoutForRead (int value)
 Set the timeout value for reading.
 
int getTimeoutForRead ()
 Get the timeout value for reading.
 
void clearResponseAndRequestQueue ()
 Clears the pending http responses and http requests If defined, the method uses the ClearRequestPredicate and ClearResponsePredicate to check for each request/response which to delete.
 
void setClearRequestPredicate (ClearRequestPredicate predicate)
 Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.
 
void setClearResponsePredicate (ClearResponsePredicate predicate)
 Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.
 

Static Public Member Functions

static HttpClientgetInstance ()
 Get instance of HttpClient.
 
static void destroyInstance ()
 Release the instance of HttpClient.
 

Static Public Attributes

static const int RESPONSE_BUFFER_SIZE = 256
 The buffer size of _responseMessage.
 

Detailed Description

Singleton that handles asynchronous http requests.

Once the request completed, a callback will issued in main thread when it provided during make request.

NA

Member Function Documentation

static HttpClient* getInstance ( )
static

Get instance of HttpClient.

Returns
the instance of HttpClient.
void enableCookies ( const char *  cookieFile)

Enable cookie support.

Parameters
cookieFilethe filepath of cookie file.
const std::string& getCookieFilename ( )

Get the cookie filename.

Returns
the cookie filename
void setSSLVerification ( const std::string &  caFile)

Set root certificate path for SSL verification.

Parameters
caFilea full path of root certificate.if it is empty, SSL verification is disabled.
const std::string& getSSLVerification ( )

Get the ssl CA filename.

Returns
the ssl CA filename
void send ( HttpRequest request)

Add a get request to task queue.

Parameters
requesta HttpRequest object, which includes url, response callback etc. please make sure request->_requestData is clear before calling "send" here.
void sendImmediate ( HttpRequest request)

Immediate send a request.

Parameters
requesta HttpRequest object, which includes url, response callback etc. please make sure request->_requestData is clear before calling "sendImmediate" here.
void setTimeoutForConnect ( int  value)

Set the timeout value for connecting.

Parameters
valuethe timeout value for connecting.
int getTimeoutForConnect ( )

Get the timeout value for connecting.

Returns
int the timeout value for connecting.
void setTimeoutForRead ( int  value)

Set the timeout value for reading.

Parameters
valuethe timeout value for reading.
int getTimeoutForRead ( )

Get the timeout value for reading.

Returns
int the timeout value for reading.
void setClearRequestPredicate ( ClearRequestPredicate  predicate)
inline

Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.

Parameters
predicatefunction that will be called
void setClearResponsePredicate ( ClearResponsePredicate  predicate)
inline

Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.

Parameters
cbpredicate function that will be called

The documentation for this class was generated from the following file: