41 static const char* requestF =
"GET %s HTTP/1.0\r\n\r\n";
42 static const UINT32 requestFLen=strlen(requestF);
49 UINT32 len = requestFLen + strlen((
char *)url);
51 sprintf((
char *)requestS, requestF, (
const char *)url);
52 len = strlen((
char *)requestS);
83 UINT8 requestF[] =
"POST %s HTTP/1.0\r\nContent-length: %u\r\n\r\n";
93 len = strlen((
char *)requestF) + strlen((
char *)url) + 30;
95 sprintf((
char *)requestS, (
char *)requestF, (
char *)url, dataLen);
96 len = strlen((
char *)requestS);
130 if(contentLength!=NULL)
134 char *line =
new char[255];
138 UINT64 currentTime = 0, endTime = 0;
142 set64(endTime,currentTime);
143 add64(endTime,msTimeOut);
164 if( (ret ==
E_AGAIN) && (msTimeOut > 0) )
174 msTimeOut=
diff64(endTime,currentTime);
178 if(
byte ==
'\r' ||
byte ==
'\n')
187 while(
byte !=
'\n' && i<255 && ret > 0 );
194 if(strncmp(line,
"HTTP", 4) == 0)
196 if(statusCode!=NULL && strlen(line)>9)
198 *statusCode = atoi(line+9);
200 if(strstr(line,
"200 OK") == NULL)
202 CAMsg::printMsg(LOG_CRIT,
"HttpClient: Error: Server returned: '%s'.\n",line);
209 else if( (strncmp(line,
"Content-length: ", 16) == 0) ||
210 (strncmp(line,
"Content-Length: ", 16) == 0))
212 *contentLength = (
UINT32) atol(line+16);
218 while(strlen(line) > 0);
SINT32 getcurrentTimeMillis(UINT64 &u64Time)
Gets the current Systemtime in milli seconds.
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
UINT32 diff64(const UINT64 &bigop, const UINT64 &smallop)
void add64(UINT64 &op1, UINT32 op2)
bool isLesser64(UINT64 &smallOp1, UINT64 &bigOp2)
void set64(UINT64 &op1, UINT32 op2)
SINT32 sendGetRequest(const UINT8 *url)
Sends a HTTP GET request to the server.
CASocket * m_pSocket
the socket connection to the http server
SINT32 sendPostRequest(const UINT8 *url, const UINT8 *data, const UINT32 dataLen)
Sends a HTTP POST request to the server.
SINT32 getContent(UINT8 *a_pContent, UINT32 *a_pLength)
Retruns the content of the response.
SINT32 parseHTTPHeader(UINT32 *contentLength, UINT32 *statusCode=NULL, UINT32 msTimeOut=3000)
receives the HTTP header and parses the content length
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 getNonBlocking(bool *b)
virtual SINT32 setNonBlocking(bool b)
virtual SINT32 sendFullyTimeOut(const UINT8 *buff, UINT32 len, UINT32 msTimeOut, UINT32 msTimeOutSingleSend)
Sends all data over the network.