CHttpFile Read Problem
-
Hi When i read the returned data from the server in data chunks of 2048 size it is appending the server URL with each chunk read.I have the code like: m_strResponseData.Empty(); do { memset(szBuf,0x00,sizeof(szBuf)); nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); m_strResponseData += szBuf; if(nBytesRead < CHUNK_SIZE) break; }while(nBytesRead == CHUNK_SIZE); But when i run this program in debug mode it is not appending any URL in the data returned but in release mode it is appending the server URL in each chunk read. I don't want server URL with every chunk size read. Can any body tell me how is it appending the server URL with the data I read from the server. Thanks Shailesh
-
Hi When i read the returned data from the server in data chunks of 2048 size it is appending the server URL with each chunk read.I have the code like: m_strResponseData.Empty(); do { memset(szBuf,0x00,sizeof(szBuf)); nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); m_strResponseData += szBuf; if(nBytesRead < CHUNK_SIZE) break; }while(nBytesRead == CHUNK_SIZE); But when i run this program in debug mode it is not appending any URL in the data returned but in release mode it is appending the server URL in each chunk read. I don't want server URL with every chunk size read. Can any body tell me how is it appending the server URL with the data I read from the server. Thanks Shailesh
aman2006 wrote: m_strResponseData += szBuf; That's the problem.
szBuf
is usually not going to be zero-terminated, but you're treating it like it is. You're seeing the server URL in there because that just happens to be in memory right after the buffer. Change it to:m_strResponseData += CString ( (LPCSTR) szBuf, nBytesRead );
--Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- #include "witty-quote.h"
-
aman2006 wrote: m_strResponseData += szBuf; That's the problem.
szBuf
is usually not going to be zero-terminated, but you're treating it like it is. You're seeing the server URL in there because that just happens to be in memory right after the buffer. Change it to:m_strResponseData += CString ( (LPCSTR) szBuf, nBytesRead );
--Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- #include "witty-quote.h"
-
Thanks Mike u r rock, but i want to ask u why it is giving the right data without http in debug mode. thanks shailesh
Dumb luck. The layout of things in memory is much different in debug mode, due to the CRT's debug checks to catch buffer under/overrun errors. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Actual sign at the laundromat I go to: "No tinting or dying."