Download file using CInternetSession [modified]
-
Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;// Open and send the request
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);pHttpFile->AddRequestHeaders(szHeaders); pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW); pHttpFile->SendRequest(); pHttpFile->QueryInfoStatusCode(dwRet);//getting 200 int nFileLen = pFile->GetLength(); //getting 7
why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
-
Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;// Open and send the request
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);pHttpFile->AddRequestHeaders(szHeaders); pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW); pHttpFile->SendRequest(); pHttpFile->QueryInfoStatusCode(dwRet);//getting 200 int nFileLen = pFile->GetLength(); //getting 7
why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
I think you can try the function URLDownloadToFile(). http://msdn.microsoft.com/en-us/library/ms775123(v=vs.85).aspx[^]
-
Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;// Open and send the request
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);pHttpFile->AddRequestHeaders(szHeaders); pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW); pHttpFile->SendRequest(); pHttpFile->QueryInfoStatusCode(dwRet);//getting 200 int nFileLen = pFile->GetLength(); //getting 7
why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
-
john5632 wrote:
int nFileLen = pFile->GetLength(); //getting 7
where is
pFile
defined and initialised? It does not appear in this code snippet.I must get a clever new signature for 2011.
-
Hi, I am trying to download a zip file from server using CInternetSession. But i am getting incorrect size from server. My application is unicode and code as below:
pConnection = session.GetHttpConnection((LPCTSTR)strServerName, (INTERNET_PORT)nPort);//, (LPCTSTR)NULL, (LPCTSTR)NULL);
LPCTSTR pstrAcceptTypes = NULL;
LPCTSTR pstrVersion = NULL;// Open and send the request
pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, &pstrAcceptTypes, pstrVersion, HttpRequestFlags);pHttpFile->AddRequestHeaders(szHeaders); pHttpFile->AddRequestHeaders(\_T("User-Agent: GetWebFile/1.0\\r\\n"), HTTP\_ADDREQ\_FLAG\_ADD\_IF\_NEW); pHttpFile->SendRequest(); pHttpFile->QueryInfoStatusCode(dwRet);//getting 200 int nFileLen = pFile->GetLength(); //getting 7
why I am getting incorrect size? Anything wrong in this code? Same code was working with ANSI build and not working with unicode build.
modified on Thursday, January 13, 2011 5:43 AM
-
-
Previously code was in ANSI and working fine but now I converted it to UNICODE and getting this issue. Any problem with API to transdfr the string to server into UNOCODE format?
john5632 wrote:
Any problem with API to transdfr the string to server into UNOCIDE format?
Assuming both ends are working in Unicode there should be no problems. You need to check both ends are following the same rules.
I must get a clever new signature for 2011.