tfHttpcUserGetResponseBody
Table of Contents >> Application Reference >> Web Client
#include <trsocket.h> |
int tfHttpcUserGetResponseBody | ( |
ttHttpcUserConHandle conHandle, | |
char* bufferPtr, | |
int* bufferLenPtr, | |
int timeOut, | |
int flags | |
); |
Function Description
Receive part or all of the HTTP message body. This API can be called multiple times to retrieve the whole HTTP body. If the user calls this API before calling tfHttpcUserGetResponseHeaders() and/or tfHttpcUserGetResponseStatusLine(), this API receives the status line and headers first. When the return error code is TM_ENOERROR and the byte received is 0, the entire body has been received successfully.
In blocking mode, this API blocks until the user buffer is filled up, the entire body is received, the time out period has elapsed, or an error has occurred.
In non-blocking mode, this API gets what is on the socket and returns immediately. The user needs to check the return code for the receiving status. When TM_EWOULDBLOCK is returned, none or only partial body is received. The user has two choices:
- Call this API again and again(polling mode) until it returns TM_ENOERROR indicating the entire response body has been received, or until an error occurs.
- Call tfHttpcUserExecute() periodically and wait for the event handler to be notified. This requires a non-NULL event handler to be passed to tfHttpcUserOpen. When TM_HTTPC_EVENT_RECV_READY is notified, user may call this API again to receive the response.
Setting the TM_HTTPC_FLAG_END flag: If the user expects an empty response body (as it is the case with the HEAD method), the user should call tfHttpcUserGetResponseBody() with the TM_HTTPC_FLAG_END flag ORed in the last parameter. This will allow the next method line to succeed.
Parameters
- conHandle
- User connection handle
- bufferPtr
- Pointer to the user buffer
- bufferLenPtr
- Pointer to length of the user buffer
- timeOut
- Time out value in seconds. Specify -1 for infinite time out.
- flags
- ORable flags:
- TM_BLOCKING_ON, blocking mode.
- TM_BLOCKING_OFF, non-blocking mode.
- TM_HTTPC_FLAG_END, set this flag when expecting an empty response body
Returns
- TM_ENOERROR
- The entire body has been received sucessfully
- TM_ETIMEDOUT
- Used for blocking mode. It indicates no or partial body is received in the time out period.
- TM_EWOULDBLOCK
- For non-blocking mode, only partial body is received
- TM_EINVAL
- Invalid conHandle or bufferPtr
- TM_ENOTCONN
- Not connected.
- TM_EPERM
- The operation is not permitted