Syntax
bool HTTP_GetResponse(
HTTP_REQUEST_HANDLE handle,
char *phase,
unsigned int *pHttpResponse,
char **ppContent,
unsigned int *pContentLength,
char **ppHeader,
unsigned int *pHeaderLength
);
Parameters
- handle
- [in] Specify the HTTP request handle obtained by the HTTP_CreateRequest function.
- phase
-
[out] Returns the current phase. Returns one of the following values:
Value Description HTTP_REQUEST_INIT Not yet connected to the HTTP server. HTTP_REQUEST_CONNECTED Successfully connected with the HTTP server and sending an HTTP request and the send data. HTTP_REQUEST_UPLOAD_COMPLETE If there is send data, transmission of the send data has ended. HTTP_REQUEST_FINISHED Reception of the HTTP response from the HTTP server is complete. HTTP_REQUEST_CONNECTION_ERROR Failed to connect to the HTTP server. HTTP_REQUEST_TIMEOUT A timeout occurred while waiting for a response. HTTP_REQUEST_SYSTEM_ERROR A system error was detected. - pHttpResponse
- [out] Returns the status code of the HTTP response.
- ppContent
- [out] Returns a pointer to the memory that stores the received data.
- pContentLength
- [out] Returns the length of the received data.
- ppHeader
- [out] Returns a pointer to the memory that stores the HTTP response header.
- pHeaderLength
- [out] Returns the length of the HTTP response header.
Return value
Returns true if the function succeeds, false otherwise.
Remarks
When this function is called with the HTTP request handle obtained by HTTP_CreateRequest function, the specified HTTP request is sent and the HTTP response is received.While monitoring the value of the phase returned in phase , keep calling this function until an HTTP response is received.
When the phase is HTTP_REQUEST_INIT, HTTP_REQUEST_CONNECTED or HTTP_REQUEST_UPLOAD_COMPLETE, it means that processing is currently in progress.
In this case, continue monitoring.
If the phase is HTTP_REQUEST_CONNECTION_ERROR, HTTP_REQUEST_TIMEOUT, or HTTP_REQUEST_SYSTEM_ERROR, it means that the transmission of HTTP request or the reception of HTTP response failed.
In this case, stop monitoring the response by this function and end the process.
When the phase is HTTP_REQUEST_FINISHED, it means that the HTTP response has been received.
In this case, check the status code returned by the server with pHttpResponse.
ppContent returns a pointer to the memory that stores the received data, and ppHeader returns a pointer to the memory that stores the HTTP response header.
The memories returned by the ppContent and ppHeader are freed by calling HTTP_CloseRequest function. Read those memories before calling the HTTP_CloseRequest function.
Requirements
Header file:
lib.hLibrary file:
http_request.h
libHttpRequest.a
libSTARTUPOPH5000.a
Sample
int result_code;
char responsePhase;
unsigned int responseStatus;
char *content;
unsigned int content_length;
char *header;
unsigned int headerLength;
bool bExit = false;
...
while (1)
{
//Wait for HTTP response
if (!HTTP_GetResponse(
hRequest,
&responsePhase,
&responseStatus,
&content,
&content_length,
&header,
&headerLength))
{
result_code = xxxx_SYSTEM_ERROR;
break;
}
switch(responsePhase)
{
case HTTP_REQUEST_CONNECTION_ERROR:
case HTTP_REQUEST_SYSTEM_ERROR:
case HTTP_REQUEST_TIMEOUT:
result_code = xxxx_SERVER_CONNECTION_ERROR;
bExit = true;
break;
case HTTP_REQUEST_FINISHED:
if (responseStatus != 200)
{
bExit = true;
result_code = xxxx_SERVER_RESPONSE_ERROR;
break;
}
// Got response....
....
result_code = xxxx_SUCCESS;
bExit = true;
break;
}
if (bExit)
break;
Idle();
}
Last updated: 2020/10/28