Half image is received by using WinHTTP

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Verdana,Arial,sans-serif
<span style="font-size:12px; line-height:15px Hi,

I am using the following<span style="font-size:12px; line-height:15px code, and it works for binary image download, but the problem is:
<span style="font-size:12px; line-height:15px <br/>
For an image file with 18k size on server side, only 4k can be download and just half of the image can be seen on the client side. <br/>
<br/>
Any ideas?<br/>
<br/>
Thanks.


void Abc::downloadImage()
{
<span style="font-size:12px; line-height:15px DWORD dwSize = 0;
<span style="font-size:12px; line-height:15px <span style="white-space:pre DWORD dwDownloaded = 0;
<span style="font-size:12px; line-height:15px <span style="white-space:pre LPSTR pszOutBuffer;
<span style="font-size:12px; line-height:15px <span style="white-space:pre BOOL bResults = FALSE;
<span style="font-size:12px; line-height:15px <span style="white-space:pre HINTERNET hSession = NULL,
<span style="font-size:12px; line-height:15px <span style="white-space:pre hConnect = NULL,
<span style="font-size:12px; line-height:15px <span style="white-space:pre hRequest = NULL;
<span style="font-size:12px; line-height:15px
<span style="font-size:12px; line-height:15px <span style="white-space:pre hSession = WinHttpOpen( L"WinHTTP",
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_NO_PROXY_NAME,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_NO_PROXY_BYPASS, 0);
<span style="font-size:12px; line-height:15px
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (hSession)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre hConnect = WinHttpConnect(hSession, L"localhost", INTERNET_DEFAULT_HTTP_PORT, 0);<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="white-space:pre; font-size:12px; line-height:15px
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (hConnect)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre hRequest = WinHttpOpenRequest( hConnect, L"GET",
<span style="font-size:12px; line-height:15px <span style="white-space:pre L"/Abc/images/a.jpg",
<span style="font-size:12px; line-height:15px <span style="white-space:pre NULL, WINHTTP_NO_REFERER,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_DEFAULT_ACCEPT_TYPES,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_FLAG_REFRESH);<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <br/>

<span style="font-size:12px; line-height:15px <span style="white-space:pre if (hRequest)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre bResults = WinHttpSendRequest( hRequest,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_NO_ADDITIONAL_HEADERS, 0,
<span style="font-size:12px; line-height:15px <span style="white-space:pre WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <br/>

<span style="font-size:12px; line-height:15px <span style="white-space:pre if (bResults)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre bResults = WinHttpReceiveResponse( hRequest, NULL);<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <br/>

<span style="font-size:12px; line-height:15px <span style="white-space:pre if (bResults)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre dwSize = 0;
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre printf("Error %u in WinHttpQueryDataAvailable.n", GetLastError());
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <span style="white-space:pre
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (dwSize > 0)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre pszOutBuffer = new char[dwSize+1];
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <span style="white-space:pre
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (!pszOutBuffer)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre printf("Out of memoryn");
<span style="font-size:12px; line-height:15px <span style="white-space:pre dwSize=0;
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <span style="white-space:pre else
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (dwSize>0)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre ZeroMemory(pszOutBuffer, dwSize+1);
<span style="font-size:12px; line-height:15px <span style="white-space:pre if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded))
<span style="font-size:12px; line-height:15px <span style="white-space:pre printf("Error %u in WinHttpReadData.n", GetLastError());<span style="white-space:pre

<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px
<span style="font-size:12px; line-height:15px <span style="white-space:pre HANDLE hFile;
<span style="font-size:12px; line-height:15px <span style="white-space:pre DWORD dwNumWritten;
<span style="font-size:12px; line-height:15px <span style="white-space:pre BOOL bTest;
<span style="font-size:12px; line-height:15px <span style="white-space:pre
<span style="font-size:12px; line-height:15px <span style="white-space:pre std::ofstream outfile;
<span style="font-size:12px; line-height:15px <span style="white-space:pre outfile.open("D:\1.jpg",std::ofstream::binary);
<span style="font-size:12px; line-height:15px <span style="white-space:pre outfile.write(pszOutBuffer,dwSize);
<span style="font-size:12px; line-height:15px <span style="white-space:pre outfile.close();
<span style="font-size:12px; line-height:15px <span style="white-space:pre // Close any open handles.
<span style="font-size:12px; line-height:15px <span style="white-space:pre if( hRequest )
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre WinHttpCloseHandle( hRequest );
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="font-size:12px; line-height:15px <br/>

<span style="font-size:12px; line-height:15px <span style="white-space:pre if( hConnect)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre WinHttpCloseHandle( hConnect );
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<span style="white-space:pre; font-size:12px; line-height:15px
<span style="font-size:12px; line-height:15px <span style="white-space:pre if( hSession)
<span style="font-size:12px; line-height:15px <span style="white-space:pre {
<span style="font-size:12px; line-height:15px <span style="white-space:pre WinHttpCloseHandle( hSession );
<span style="font-size:12px; line-height:15px <span style="white-space:pre }
<div style="font-size:12px; line-height:15px }


View the full article
 

Similar threads

Back
Top