Discussion:
force HttpQueryInfo to get "304 Not Modified" status code
(too old to reply)
x***@o2.pl
2006-10-03 02:39:24 UTC
Permalink
I have a problem with this code:

void *hInternet, *hConnect, *hRequest;
unsigned char status_code[4], *lpBuffer;
unsigned int dwBufferLength, dwBufferTotal, dwNumberOfBytesRead;
hInternet =3D InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0);
hConnect =3D InternetConnect(hInternet, "foobar2000.org", 80, 0, 0, INTE=
RNET_SERVICE_HTTP, 0, 0);
hRequest =3D HttpOpenRequest(hConnect, 0, 0, 0, 0, 0, 0, 0);
HttpSendRequest(hRequest, 0, 0, 0, 0);
dwBufferLength =3D 4;
HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, status_code, &dwBufferLe=
ngth, 0);
lpBuffer =3D malloc(10240);
InternetReadFile(hRequest, lpBuffer, 10240, &dwNumberOfBytesRead);
for(dwBufferTotal =3D 0; dwNumberOfBytesRead !=3D 0; dwBufferTotal +=3D =
dwNumberOfBytesRead)
{
InternetReadFile(hRequest, lpBuffer + dwBufferTotal, 10240 - dw=
BufferTotal, &dwNumberOfBytesRead);
}
free(lpBuffer);
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return;

After executing it twice, server responds with "304 Not Modified" status=
code, but wininet loads response from cache and HttpQueryInfo gets "200=
OK". How can I force HttpQueryInfo to get real "304 Not Modified" statu=
s code?

Thanks
Vladimir Scherbina
2006-10-04 08:30:40 UTC
Permalink
I think you need to clear cache in wininet. Read this:
http://support.microsoft.com/kb/q311289/ or as another option use
INTERNET_OPTION_BYPASS_EDITED_ENTRY as a flag for InternetSetOption.
--
Vladimir
x***@o2.pl
2006-10-04 13:17:25 UTC
Permalink
Unfortunatly it doesn't work.

When I'm using DeleteUrlCacheEntry, it simpy does'nt send "if-Modified-Since" header, so I'm receiving "200 OK" status code no matter how many times I'm executing my code.

Setting flag INTERNET_OPTION_BYPASS_EDITED_ENTRY with hInternet, hConnect or hRequest results with 12018 error (ERROR_INTERNET_INCORRECT_HANDLE_TYPE - The type of handle supplied is incorrect for this operation). Using 0 as hInternet handle doesn't change anything.
Loading...