tfHttpcUserGetResponseHeaders
Table of Contents >> Application Reference >> Web Client
| #include <trsocket.h> |
| int tfHttpcUserGetResponseHeaders | ( |
| ttHttpcUserConHandle conHandle, | |
| char *** headerValPtr, | |
| int timeOut, | |
| int flags | |
| ); |
Function Description
Get the headers from the received HTTP response message. If user calls this API before calling tfHttpcUserGetResponseStatusLine(), this API will try to receive the status line first.
In blocking mode, user blocks until the headers have been 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 sending status. When TM_ENOERROR is returned, the headers have been received. When TM_EWOULDBLOCK is returned, not all the headers have been received.
When TM_EWOULDBLOCK is returned, user has two choices:
- Call this API again and again until it returns TM_ENOERROR indicating the response headers 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.
Parameters
- conHandle
- HTTP client connection handle.
- headerValPtr
- Pointer to a variable that receives a pointer to an array of strings for each possible HTTP header, indexed by ttHttpUserHeaderType. For HTTP headers that havenât received yet, this pointer entry is NULL. For example, if you pass headerValPtr as &headerArray then headerArray[TM_HTTP_HEADER_COOKIE] is the HTTP cookie that the server returned, or NULL if no such header was returned. The storage for the array is contained within and owned by the descriptor associated with conHandle.
- timeOut
- Receiving time out period for blocking mode. Specify -1 for infinite timeout; the caller will be blocked until all headers have been received or an error occurred.
- flags
- ORable flags:
- TM_BLOCKING_ON, blocking mode.
- TM_BLOCKING_OFF, non-blocking mode
Returns
- TM_ENOERROR
- The status line has been received successfully.
- TM_ETIMEDOUT
- Used for blocking mode. The time out period has elapsed before the status line is received. User could choose call this API again or close the connection.
- TM_EWOULDBLOCK
- Used for non-blocking mode only. The status line hasnât been received yet. User should call this API again. User may wait for event TM_HTTPC_EVENT_RECV_READY before calling again.
- TM_EINVAL
- Invalid parameter(s).
- TM_ENOTCONN
- Not connected.
- TM_EPERM
- The operation is not permitted.
- TM_EFORMAT
- The response is in wrong format. User should close the connection.
- TM_ENOBUFF
- Insufficient memory.