Use CHttpFile to correctly read data from the server.
Some time ago, I found a problem when prompted the module for software upgrade, that is, the CHttpFile object cannot be used to get the correct response data length from the server, whether it is using the CHttpFile: QueryInfo method, still use the CHttpFile: GetLength method. The length obtained each time is not fixed, causing data read errors. The Code is as follows:
# Define READ_BUFFER_LENGTH 1024
# Define PAGE_BUFFER_SIZE 1024*4
Char * CHttpClient: ReadData (CHttpFile * pFile)
{
Char * pUtf8 = (char *) malloc (PAGE_BUFFER_SIZE );
UINT bufLen = PAGE_BUFFER_SIZE;
UINT recLen = 0;
UINT recSize = 0;
Char * pDest = pUtf8;
While (recLen = pFile-> Read (pDest, READ_BUFFER_LENGTH)> 0)
{
RecSize + = recLen;
If (recSize + READ_BUFFER_LENGTH> bufLen)
{
BufLen + = PAGE_BUFFER_SIZE;
PUtf8 = (char *) realloc (pUtf8, bufLen );
PDest = pUtf8 + recSize;
}
Else
{
PDest + = recLen;
}
}
PUtf8 [recSize] = '\ 0 ';
Return pUtf8;
}