Defines the object which users must packed for HttpClient::send(HttpRequest*) method.
More...
#include <HttpRequest.h>
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
@lua NA
◆ HttpRequest()
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.
◆ autorelease()
Override autorelease method to avoid developers to call it.
If this function was called, it would trigger assert in debug mode
- Returns
- Object* always return nullptr.
◆ setRequestType()
void setRequestType |
( |
Type | type | ) |
|
|
inline |
◆ getRequestType()
Type getRequestType |
( |
| ) |
const |
|
inline |
◆ setUrl()
void setUrl |
( |
std::string_view | 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
-
◆ getUrl()
std::string_view getUrl |
( |
| ) |
const |
|
inline |
Get the url address of HttpRequest object.
- Returns
- const char* the pointer of _url.
◆ setRequestData()
void setRequestData |
( |
const char * | buffer, |
|
|
size_t | len ) |
|
inline |
Set the request data of HttpRequest object.
- Parameters
-
buffer | the buffer of request data, it support binary data. |
len | the size of request data. |
◆ getRequestData()
char * getRequestData |
( |
| ) |
|
|
inline |
Get the request data pointer of HttpRequest object.
- Returns
- char* the request data pointer.
◆ getRequestDataSize()
ssize_t getRequestDataSize |
( |
| ) |
const |
|
inline |
Get the size of request data.
- Returns
- ssize_t the size of request data
◆ setTag()
void setTag |
( |
std::string_view | tag | ) |
|
|
inline |
Set a string tag to identify your request.
This tag can be found in HttpResponse->getHttpRequest->getTag().
- Parameters
-
◆ getTag()
std::string_view 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
◆ setUserData()
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
-
pUserData | the string pointer |
◆ getUserData()
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.
◆ setResponseCallback()
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
-
callback | the ccHttpRequestCallback function. |
◆ getCallback()
const ccHttpRequestCallback & getCallback |
( |
| ) |
const |
|
inline |
Get ccHttpRequestCallback callback function.
- Returns
- const ccHttpRequestCallback& ccHttpRequestCallback callback function.
◆ setHeaders()
void setHeaders |
( |
const std::vector< std::string > & | headers | ) |
|
|
inline |
Set custom-defined headers.
- Parameters
-
headers | The string vector of custom-defined headers. |
◆ getHeaders()
const std::vector< std::string > & getHeaders |
( |
| ) |
const |
|
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: