Cocos2d-x  v3.17
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
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. More...
 
var ~HttpRequest ()
 Destructor. More...
 
Refautorelease ()
 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 () const
 Get the request type of HttpRequest object. More...
 
void setUrl (const std::string &url)
 Set the url address of HttpRequest object. More...
 
var setUrl ( var url)
 Set the url address of HttpRequest object. More...
 
const char * getUrl () const
 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 () const
 Get the size of request data. More...
 
var getRequestDataSize ()
 Get the size of request data. More...
 
void setTag (const std::string &tag)
 Set a string tag to identify your request. More...
 
const char * getTag () const
 Get the string tag to identify the request. More...
 
void setUserData (void *pUserData)
 Set user-customed data of HttpRequest object. More...
 
void * getUserData () const
 Get the user-customed data pointer which were pre-setted. More...
 
var 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...
 
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 () const
 Get the target of callback selector function, mainly used by HttpClient. More...
 
_prxy getSelector () const
 Get _prxy object by the _pSelector. More...
 
var getSelector ()
 Get _prxy object by the _pSelector. More...
 
const ccHttpRequestCallback & getCallback () const
 Get ccHttpRequestCallback callback function. More...
 
void setHeaders (const std::vector< std::string > &headers)
 Set custom-defined headers. More...
 
std::vector< std::string > getHeaders () const
 Get custom headers. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
local 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. More...
 

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.
 

Detailed Description

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

Please refer to tests/test-cpp/Classes/ExtensionTest/NetworkTest/HttpClientTest.cpp as a sample

Since
v2.0.2

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 Please refer to HttpRequestTest.cpp to find its usage.

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 Please refer to HttpRequestTest.cpp to find its usage.

virtual ~HttpRequest ( )
inlinevirtual

Destructor.

var ~HttpRequest ( )
inlinevirtual

Destructor.

Member Function Documentation

Ref* autorelease ( )
inline

Override autorelease method to avoid developers to call it.

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

Returns
Ref* 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

Returns
Ref* 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.

Parameters
typethe 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.

Parameters
typethe request type.
Type getRequestType ( ) const
inline

Get the request type of HttpRequest object.

Returns
HttpRequest::Type.
var getRequestType ( )
inline

Get the request type of HttpRequest object.

Returns
HttpRequest::Type.
void setUrl ( const std::string &  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"

Parameters
urlthe string object.
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"

Parameters
urlthe string object.
const char* getUrl ( ) const
inline

Get the url address of HttpRequest object.

Returns
const char* the pointer of _url.
var getUrl ( )
inline

Get the url address of HttpRequest object.

Returns
const char* the pointer of _url.
void setRequestData ( const char *  buffer,
size_t  len 
)
inline

Set the request data of HttpRequest object.

Parameters
bufferthe buffer of request data, it support binary data.
lenthe size of request data.
var setRequestData ( var  buffer,
var  len 
)
inline

Set the request data of HttpRequest object.

Parameters
bufferthe buffer of request data, it support binary data.
lenthe size of request data.
char* getRequestData ( )
inline

Get the request data pointer of HttpRequest object.

Returns
char* the request data pointer.
var getRequestData ( )
inline

Get the request data pointer of HttpRequest object.

Returns
char* the request data pointer.
ssize_t getRequestDataSize ( ) const
inline

Get the size of request data.

Returns
ssize_t the size of request data
var getRequestDataSize ( )
inline

Get the size of request data.

Returns
ssize_t the size of request data
void setTag ( const std::string &  tag)
inline

Set a string tag to identify your request.

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

Parameters
tagthe string object.
var setTag ( var  tag)
inline

Set a string tag to identify your request.

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

Parameters
tagthe string object.
const char* getTag ( ) const
inline

Get the string tag to identify the request.

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

Returns
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.

Returns
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.

Parameters
pUserDatathe string pointer
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.

Parameters
pUserDatathe string pointer
void* getUserData ( ) const
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.

Returns
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.

Returns
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.

Parameters
pTargetthe target object pointer.
pSelectorthe 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.

Parameters
pTargetthe target object pointer.
pSelectorthe 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.

Parameters
pTargetthe target object pointer.
pSelectorthe 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.

Parameters
pTargetthe target object pointer.
pSelectorthe 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.

Parameters
callbackthe 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.

Parameters
callbackthe ccHttpRequestCallback function.
Ref* getTarget ( ) const
inline

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

Returns
Ref* the target of callback selector function
var getTarget ( )
inline

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

Returns
Ref* the target of callback selector function
_prxy getSelector ( ) const
inline

Get _prxy object by the _pSelector.

Returns
_prxy the _prxy object
var getSelector ( )
inline

Get _prxy object by the _pSelector.

Returns
_prxy the _prxy object
const ccHttpRequestCallback&
getCallback
( ) const
inline

Get ccHttpRequestCallback callback function.

Returns
const ccHttpRequestCallback& ccHttpRequestCallback callback function.
var getCallback ( )
inline

Get ccHttpRequestCallback callback function.

Returns
const ccHttpRequestCallback& ccHttpRequestCallback callback function.
void setHeaders ( const std::vector< std::string > &  headers)
inline

Set custom-defined headers.

Parameters
headersThe string vector of custom-defined headers.
var setHeaders ( var  headers)
inline

Set custom-defined headers.

Parameters
headersThe string vector of custom-defined headers.
std::vector<std::string> getHeaders ( ) const
inline

Get custom headers.

Returns
std::vector<std::string> the string vector of custom-defined headers.
var getHeaders ( )
inline

Get custom headers.

Returns
std::vector<std::string> the string vector of custom-defined headers.

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