NetServices Stack source
Dependents: HelloWorld ServoInterfaceBoardExample1 4180_Lab4
Diff: services/http/client/HTTPClient.cpp
- Revision:
- 9:c79fa4034f5b
- Parent:
- 5:dd63a1e02b1b
--- a/services/http/client/HTTPClient.cpp Wed Jul 28 12:45:32 2010 +0000 +++ b/services/http/client/HTTPClient.cpp Thu Aug 05 14:32:43 2010 +0000 @@ -21,6 +21,7 @@ THE SOFTWARE. */ +#include "core/netservice.h" #include "HTTPClient.h" #include "../util/base64.h" #include "../util/url.h" @@ -80,7 +81,7 @@ return HTTP_PROCESSING; } -#ifdef __LINKER_BUG_SOLVED__ +#if 0 //For info only template<class T> HTTPResult HTTPClient::get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking { @@ -103,7 +104,7 @@ return HTTP_PROCESSING; } -#ifdef __LINKER_BUG_SOLVED__ +#if 0 //For info only template<class T> HTTPResult HTTPClient::post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking { @@ -132,7 +133,7 @@ m_pCbMeth = NULL; } -#ifdef __LINKER_BUG_SOLVED__ +#if 0 //For info only template<class T> void HTTPClient::setOnResult( T* pItem, void (T::*pMethod)(NtpResult) ) { @@ -304,11 +305,11 @@ if(m_state == HTTP_READ_DATA_INCOMPLETE) //First try to complete buffer copy { readLen = m_bufRemainingLen; - if (readLen == 0) + /* if (readLen == 0) { m_state = HTTP_READ_DATA; continue; - } + }*/ } else { @@ -317,16 +318,23 @@ { return readLen; } + + DBG("%d bytes read\n", readLen); + m_pBufRemaining = m_buf; } - /* if (readLen == 0) + if (readLen == 0) { m_state = HTTP_READ_DATA; return len; - }*/ + } + + DBG("Trying to write %d bytes\n", readLen); int writtenLen = m_pDataIn->write(m_pBufRemaining, readLen); m_dataPos += writtenLen; + + DBG("%d bytes written\n", writtenLen); if(writtenLen<readLen) //Data was not completely written { @@ -450,7 +458,7 @@ { //Write chunk header char chunkHeader[16]; - sprintf(chunkHeader, "%d\n", len); + sprintf(chunkHeader, "%d\r\n", len); int ret = m_pTCPSocket->send(chunkHeader, strlen(chunkHeader)); if(ret < 0)//Error { @@ -462,7 +470,7 @@ m_dataPos+=len; if( m_dataChunked ) { - m_pTCPSocket->send("", 2); //Chunk terminating CRLF + m_pTCPSocket->send("\r\n", 2); //Chunk-terminating CRLF } if( ( !m_dataChunked && (m_dataPos >= m_dataLen) ) || ( m_dataChunked && !len ) ) //All Data has been sent @@ -742,7 +750,7 @@ const char* HTTP_METH_STR[] = {"GET", "POST", "HEAD"}; //Req - sprintf(line, "%s %s HTTP/1.1\r\nHost: %s\n", HTTP_METH_STR[m_meth], m_path.c_str(), m_server.getName()); //Write request + sprintf(line, "%s %s HTTP/1.1\r\nHost: %s\r\n", HTTP_METH_STR[m_meth], m_path.c_str(), m_server.getName()); //Write request m_pTCPSocket->send(line, strlen(line)); DBG("Request: %s\n", line); @@ -750,11 +758,11 @@ map<string,string>::iterator it; for( it = m_reqHeaders.begin(); it != m_reqHeaders.end(); it++ ) { - sprintf(line, "%s: %s\n", (*it).first.c_str(), (*it).second.c_str() ); - DBG("%s", line); + sprintf(line, "%s: %s\r\n", (*it).first.c_str(), (*it).second.c_str() ); + DBG("\r\n%s", line); m_pTCPSocket->send(line, strlen(line)); } - m_pTCPSocket->send("",2); //End of head + m_pTCPSocket->send("\r\n",2); //End of head m_state = HTTP_WRITE_DATA; return true; }