Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
HttpRequest Class Reference

Defines the object which users must packed for HttpClient::send(HttpRequest*) method. More...

Inherits Ref.

Classes

class  _prxy
 This sub class is just for migration SEL_CallFuncND to SEL_HttpResponse,someday this way will be removed. More...
 

Public Types

enum  Type
 The HttpRequest type enum used in the HttpRequest::setRequestType.
 

Public Member Functions

 HttpRequest ()
 Constructor. More...
 
virtual ~HttpRequest ()
 Destructor.
 
var ~HttpRequest ()
 Destructor.
 
Refautorelease (void)
 Override autorelease method to avoid developers to call it. More...
 
var autorelease ()
 Override autorelease method to avoid developers to call it. More...
 
void setRequestType (Type type)
 Set request type of HttpRequest object before being sent,now it support the enum value of HttpRequest::Type. More...
 
Type getRequestType ()
 Get the request type of HttpRequest object. More...
 
var getRequestType ()
 Get the request type of HttpRequest object. More...
 
void setUrl (const char *url)
 Set the url address of HttpRequest object. More...
 
const char * getUrl ()
 Get the url address of HttpRequest object. More...
 
void setRequestData (const char *buffer, size_t len)
 Set the request data of HttpRequest object. More...
 
var setRequestData ( var buffer, var len)
 Set the request data of HttpRequest object. More...
 
char * getRequestData ()
 Get the request data pointer of HttpRequest object. More...
 
var getRequestData ()
 Get the request data pointer of HttpRequest object. More...
 
ssize_t getRequestDataSize ()
 Get the size of request data. More...
 
var getRequestDataSize ()
 Get the size of request data. More...
 
void setTag (const char *tag)
 Set a string tag to identify your request. More...
 
const char * getTag ()
 Get the string tag to identify the request. More...
 
void setUserData (void *pUserData)
 Set user-customed data of HttpRequest object. More...
 
void * getUserData ()
 Get the user-customed data pointer which were pre-setted. More...
 
void setResponseCallback (Ref *pTarget, SEL_CallFuncND pSelector)
 Set the target and related callback selector. More...
 
var setResponseCallback ( var pTarget, var pSelector)
 Set the target and related callback selector. More...
 
void setResponseCallback (Ref *pTarget, SEL_HttpResponse pSelector)
 Set the target and related callback selector of HttpRequest object. More...
 
void setResponseCallback (const ccHttpRequestCallback &callback)
 Set response callback function of HttpRequest object. More...
 
RefgetTarget ()
 Get the target of callback selector function, mainly used by HttpClient. More...
 
_prxy getSelector ()
 Get _prxy object by the _pSelector. More...
 
var getSelector ()
 Get _prxy object by the _pSelector. More...
 
const ccHttpRequestCallback & getCallback ()
 Get ccHttpRequestCallback callback function. More...
 
void setHeaders (std::vector< std::string > pHeaders)
 Set custom-defined headers. More...
 
var setHeaders ( var pHeaders)
 Set custom-defined headers. More...
 
std::vector< std::string > getHeaders ()
 Get custom headers. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
local retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
local getReferenceCount ()
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor.
 

Additional Inherited Members

- Public Attributes inherited from Ref
unsigned int _ID
 object id, ScriptSupport need public _ID
 
local _ID
 object id, ScriptSupport need public _ID
 
int _luaID
 Lua reference id.
 
local _luaID
 Lua reference id.
 
void * _scriptObject
 scriptObject, support for swift
 
local _scriptObject
 scriptObject, support for swift
 
bool _rooted
 When true, it means that the object was already rooted.
 
local _rooted
 When true, it means that the object was already rooted.
 
bool _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 
local _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 

Detailed Description

Defines the object which users must packed for HttpClient::send(HttpRequest*) method.

Constructor & Destructor Documentation

HttpRequest ( )
inline

Constructor.

Because HttpRequest object will be used between UI thread and network thread, requestObj->autorelease() is forbidden to avoid crashes in AutoreleasePool new/retain/release still works, which means you need to release it manually

var HttpRequest ( )
inline

Constructor.

Because HttpRequest object will be used between UI thread and network thread, requestObj->autorelease() is forbidden to avoid crashes in AutoreleasePool new/retain/release still works, which means you need to release it manually

Member Function Documentation

Ref* autorelease ( void  )
inline

Override autorelease method to avoid developers to call it.

If this function was called, it would trigger assert in debug mode

always return nullptr.

var autorelease (   )
inline

Override autorelease method to avoid developers to call it.

If this function was called, it would trigger assert in debug mode

always return nullptr.

void setRequestType ( Type  type)
inline

Set request type of HttpRequest object before being sent,now it support the enum value of HttpRequest::Type.

the request type.

var setRequestType ( var  type)
inline

Set request type of HttpRequest object before being sent,now it support the enum value of HttpRequest::Type.

the request type.

Type getRequestType ( )
inline

Get the request type of HttpRequest object.

HttpRequest::Type.

var getRequestType ( )
inline

Get the request type of HttpRequest object.

HttpRequest::Type.

void setUrl ( const char *  url)
inline

Set the url address of HttpRequest object.

The url value could be like these: "http://httpbin.org/ip" or "https://httpbin.org/get"

the string pointer to the url.

var setUrl ( var  url)
inline

Set the url address of HttpRequest object.

The url value could be like these: "http://httpbin.org/ip" or "https://httpbin.org/get"

the string pointer to the url.

const char* getUrl ( )
inline

Get the url address of HttpRequest object.

const char* the pointer of _url.

var getUrl ( )
inline

Get the url address of HttpRequest object.

const char* the pointer of _url.

void setRequestData ( const char *  buffer,
size_t  len 
)
inline

Set the request data of HttpRequest object.

the buffer of request data, it support binary data. the size of request data.

var setRequestData ( var  buffer,
var  len 
)
inline

Set the request data of HttpRequest object.

the buffer of request data, it support binary data. the size of request data.

char* getRequestData ( )
inline

Get the request data pointer of HttpRequest object.

char* the request data pointer.

var getRequestData ( )
inline

Get the request data pointer of HttpRequest object.

char* the request data pointer.

ssize_t getRequestDataSize ( )
inline

Get the size of request data.

ssize_t the size of request data

var getRequestDataSize ( )
inline

Get the size of request data.

ssize_t the size of request data

void setTag ( const char *  tag)
inline

Set a string tag to identify your request.

This tag can be found in HttpResponse->getHttpRequest->getTag().

the string pointer to tag

var setTag ( var  tag)
inline

Set a string tag to identify your request.

This tag can be found in HttpResponse->getHttpRequest->getTag().

the string pointer to tag

const char* getTag ( )
inline

Get the string tag to identify the request.

The best practice is to use it in your MyClass::onMyHttpRequestCompleted(sender, HttpResponse*) callback.

const char* the pointer of _tag

var getTag ( )
inline

Get the string tag to identify the request.

The best practice is to use it in your MyClass::onMyHttpRequestCompleted(sender, HttpResponse*) callback.

const char* the pointer of _tag

void setUserData ( void *  pUserData)
inline

Set user-customed data of HttpRequest object.

You can attach a customed data in each request, and get it back in response callback. But you need to new/delete the data pointer manually.

the pointer point to customed data

var setUserData ( var  pUserData)
inline

Set user-customed data of HttpRequest object.

You can attach a customed data in each request, and get it back in response callback. But you need to new/delete the data pointer manually.

the pointer point to customed data

void* getUserData ( )
inline

Get the user-customed data pointer which were pre-setted.

Don't forget to delete it. HttpClient/HttpResponse/HttpRequest will do nothing with this pointer.

void* the pointer of user-customed data.

var getUserData ( )
inline

Get the user-customed data pointer which were pre-setted.

Don't forget to delete it. HttpClient/HttpResponse/HttpRequest will do nothing with this pointer.

void* the pointer of user-customed data.

void setResponseCallback ( Ref pTarget,
SEL_CallFuncND  pSelector 
)
inline

Set the target and related callback selector.

When response come back, it would call (pTarget->*pSelector) to process something.

the target object pointer. the callback function.

var setResponseCallback ( var  pTarget,
var  pSelector 
)
inline

Set the target and related callback selector.

When response come back, it would call (pTarget->*pSelector) to process something.

the target object pointer. the callback function.

void setResponseCallback ( Ref pTarget,
SEL_HttpResponse  pSelector 
)
inline

Set the target and related callback selector of HttpRequest object.

When response come back, we would call (pTarget->*pSelector) to process response data.

the target object pointer. the SEL_HttpResponse function.

var setResponseCallback ( var  pTarget,
var  pSelector 
)
inline

Set the target and related callback selector of HttpRequest object.

When response come back, we would call (pTarget->*pSelector) to process response data.

the target object pointer. the SEL_HttpResponse function.

void setResponseCallback ( const ccHttpRequestCallback &  callback)
inline

Set response callback function of HttpRequest object.

When response come back, we would call _pCallback to process response data.

the ccHttpRequestCallback function.

var setResponseCallback ( var  callback)
inline

Set response callback function of HttpRequest object.

When response come back, we would call _pCallback to process response data.

the ccHttpRequestCallback function.

Ref* getTarget ( )
inline

Get the target of callback selector function, mainly used by HttpClient.

Ref* the target of callback selector funtion

var getTarget ( )
inline

Get the target of callback selector function, mainly used by HttpClient.

Ref* the target of callback selector funtion

_prxy getSelector ( )
inline

Get _prxy object by the _pSelector.

the _prxy object

var getSelector ( )
inline

Get _prxy object by the _pSelector.

the _prxy object

const ccHttpRequestCallback&
getCallback
( )
inline

Get ccHttpRequestCallback callback function.

ccHttpRequestCallback callback function.

var getCallback ( )
inline

Get ccHttpRequestCallback callback function.

ccHttpRequestCallback callback function.

void setHeaders ( std::vector< std::string >  pHeaders)
inline

Set custom-defined headers.

the string vector of custom-defined headers.

var setHeaders ( var  pHeaders)
inline

Set custom-defined headers.

the string vector of custom-defined headers.

std::vector<std::string> getHeaders ( )
inline

Get custom headers.

the string vector of custom-defined headers.

var getHeaders ( )
inline

Get custom headers.

the string vector of custom-defined headers.


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