cocos2d-x  2.2.3-gd2.113-rev1ec524e
Loading...
Searching...
No Matches
CCHttpRequest Class Reference

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

#include <HttpRequest.h>

Inheritance diagram for CCHttpRequest:
[legend]
Collaboration diagram for CCHttpRequest:
[legend]

Classes

class  _prxy
 

Public Types

enum  HttpRequestType {
  kHttpGet , kHttpPost , kHttpPut , kHttpDelete ,
  kHttpUnkown
}
 Use this enum type as param in setReqeustType(param) More...
 

Public Member Functions

 CCHttpRequest ()
 Constructor Because HttpRequest object will be used between UI thead and network thread, requestObj->autorelease() is forbidden to avoid crashes in CCAutoreleasePool new/retain/release still works, which means you need to release it manually Please refer to HttpRequestTest.cpp to find its usage. More...
 
virtual ~CCHttpRequest ()
 Destructor. More...
 
CCObjectautorelease (void)
 Override autorelease method to avoid developers to call it. More...
 
void setRequestType (HttpRequestType type)
 Required field for HttpRequest object before being sent. More...
 
HttpRequestType getRequestType ()
 Get back the kHttpGet/Post/... enum value. More...
 
void setUrl (const char *url)
 Required field for HttpRequest object before being sent. More...
 
const char * getUrl ()
 Get back the setted url. More...
 
void setRequestData (const char *buffer, unsigned int len)
 Option field. More...
 
char * getRequestData ()
 Get the request data pointer back. More...
 
int getRequestDataSize ()
 Get the size of request data back. More...
 
void setTag (const char *tag)
 Option field. More...
 
const char * getTag ()
 Get the string tag back to identify the request. More...
 
void setUserData (void *pUserData)
 Option field. More...
 
void * getUserData ()
 Get the pre-setted custom data pointer back. More...
 
CC_DEPRECATED_ATTRIBUTE void setResponseCallback (CCObject *pTarget, SEL_CallFuncND pSelector)
 Required field. More...
 
void setResponseCallback (CCObject *pTarget, SEL_HttpResponse pSelector)
 
CCObjectgetTarget ()
 Get the target of callback selector funtion, mainly used by CCHttpClient. More...
 
_prxy getSelector ()
 Get the selector function pointer, mainly used by CCHttpClient. More...
 
void setHeaders (std::vector< std::string > pHeaders)
 Set any custom headers. More...
 
std::vector< std::string > getHeaders ()
 Get custom headers. More...
 
- Public Member Functions inherited from CCObject
 CCObject (void)
 
virtual ~CCObject (void)
 NA. More...
 
void release (void)
 
void retain (void)
 
CCObjectautorelease (void)
 
CCObjectcopy (void)
 
bool isSingleReference (void) const
 
unsigned int retainCount (void) const
 
virtual bool isEqual (const CCObject *pObject)
 
virtual void acceptVisitor (CCDataVisitor &visitor)
 
virtual void update (float dt)
 
 CCObject (const CCObject &)
 
CCObjectoperator= (const CCObject &)
 
virtual void encodeWithCoder (DS_Dictionary *)
 
virtual bool canEncode ()
 
CCObjectType getObjType () const
 
virtual void setTag (int nTag)
 
void setObjType (CCObjectType)
 
- Public Member Functions inherited from CCCopying
virtual CCObjectcopyWithZone (CCZone *pZone)
 

Protected Attributes

HttpRequestType _requestType
 
std::string _url
 kHttpRequestGet, kHttpRequestPost or other enums More...
 
std::vector< char > _requestData
 target url that this request is sent to More...
 
std::string _tag
 used for POST More...
 
CCObject_pTarget
 user defined tag, to identify different requests in response callback More...
 
SEL_HttpResponse _pSelector
 callback target of pSelector function More...
 
void * _pUserData
 callback function, e.g. MyLayer::onHttpResponse(CCHttpClient *sender, CCHttpResponse * response) More...
 
std::vector< std::string > _headers
 You can add your customed data here. More...
 
int _requestTypeGJ
 custom http headers More...
 
bool _shouldCancel
 custom http headers More...
 
int _downloadProgress
 custom http headers More...
 
int _readTimeout
 custom http headers More...
 
- Protected Attributes inherited from CCObject
unsigned int m_uReference
 
unsigned int m_uAutoReleaseCount
 
int m_nTag
 
int m_eObjType
 
unsigned int m_uObjectIdxInArray
 

Additional Inherited Members

- Static Public Member Functions inherited from CCObject
static CCObjectcreateWithCoder (DS_Dictionary *)
 
- Public Attributes inherited from CCObject
unsigned int m_uID
 
int m_nLuaID
 

Detailed Description

defines the object which users must packed for CCHttpClient::send(HttpRequest*) method.

Please refer to samples/TestCpp/Classes/ExtensionTest/NetworkTest/HttpClientTest.cpp as a sample

Since
v2.0.2 NA NA

Member Enumeration Documentation

◆ HttpRequestType

Use this enum type as param in setReqeustType(param)

Enumerator
kHttpGet 
kHttpPost 
kHttpPut 
kHttpDelete 
kHttpUnkown 

Constructor & Destructor Documentation

◆ CCHttpRequest()

CCHttpRequest ( )
inline

Constructor Because HttpRequest object will be used between UI thead and network thread, requestObj->autorelease() is forbidden to avoid crashes in CCAutoreleasePool new/retain/release still works, which means you need to release it manually Please refer to HttpRequestTest.cpp to find its usage.

◆ ~CCHttpRequest()

virtual ~CCHttpRequest ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ autorelease()

CCObject * autorelease ( void  )
inline

Override autorelease method to avoid developers to call it.

◆ getHeaders()

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

Get custom headers.

◆ getRequestData()

char * getRequestData ( )
inline

Get the request data pointer back.

◆ getRequestDataSize()

int getRequestDataSize ( )
inline

Get the size of request data back.

◆ getRequestType()

HttpRequestType getRequestType ( )
inline

Get back the kHttpGet/Post/... enum value.

◆ getSelector()

_prxy getSelector ( )
inline

Get the selector function pointer, mainly used by CCHttpClient.

◆ getTag()

const char * getTag ( void  )
inlinevirtual

Get the string tag back to identify the request.

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

Reimplemented from CCObject.

◆ getTarget()

CCObject * getTarget ( )
inline

Get the target of callback selector funtion, mainly used by CCHttpClient.

◆ getUrl()

const char * getUrl ( )
inline

Get back the setted url.

◆ getUserData()

void * getUserData ( )
inline

Get the pre-setted custom data pointer back.

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

◆ setHeaders()

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

Set any custom headers.

◆ setRequestData()

void setRequestData ( const char *  buffer,
unsigned int  len 
)
inline

Option field.

You can set your post data here

◆ setRequestType()

void setRequestType ( HttpRequestType  type)
inline

Required field for HttpRequest object before being sent.

kHttpGet & kHttpPost is currently supported

◆ setResponseCallback() [1/2]

CC_DEPRECATED_ATTRIBUTE void setResponseCallback ( CCObject pTarget,
SEL_CallFuncND  pSelector 
)
inline

Required field.

You should set the callback selector function at ack the http request completed

◆ setResponseCallback() [2/2]

void setResponseCallback ( CCObject pTarget,
SEL_HttpResponse  pSelector 
)
inline

◆ setTag()

void setTag ( const char *  tag)
inline

Option field.

You can set a string tag to identify your request, this tag can be found in HttpResponse->getHttpRequest->getTag()

◆ setUrl()

void setUrl ( const char *  url)
inline

Required field for HttpRequest object before being sent.

◆ setUserData()

void setUserData ( void *  pUserData)
inline

Option field.

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 manully

Member Data Documentation

◆ _downloadProgress

int _downloadProgress
protected

custom http headers

Remarks
Added by RobTop. See RT_ADD for more info.

◆ _headers

std::vector<std::string> _headers
protected

You can add your customed data here.

◆ _pSelector

SEL_HttpResponse _pSelector
protected

callback target of pSelector function

◆ _pTarget

CCObject* _pTarget
protected

user defined tag, to identify different requests in response callback

◆ _pUserData

void* _pUserData
protected

callback function, e.g. MyLayer::onHttpResponse(CCHttpClient *sender, CCHttpResponse * response)

◆ _readTimeout

int _readTimeout
protected

custom http headers

Remarks
Added by RobTop. See RT_ADD for more info.

◆ _requestData

std::vector<char> _requestData
protected

target url that this request is sent to

◆ _requestType

HttpRequestType _requestType
protected

◆ _requestTypeGJ

int _requestTypeGJ
protected

custom http headers

Remarks
Added by RobTop. See RT_ADD for more info.

◆ _shouldCancel

bool _shouldCancel
protected

custom http headers

Remarks
Added by RobTop. See RT_ADD for more info.

◆ _tag

std::string _tag
protected

used for POST

◆ _url

std::string _url
protected

kHttpRequestGet, kHttpRequestPost or other enums


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