1

I'm trying to get Wininet to ignore Internet Explorer's "Work Offline" mode, for both HTTP and FTP.

So I'm trying to use InternetSetOption() with INTERNET_OPTION_IGNORE_OFFLINE. The documentation says "This is used by InternetQueryOption and InternetSetOption with a request handle." However, you can't get a request handle because if IE is in Work Offline mode then InternetConnect() will always return a null handle. Without a connection handle you can't get a request handle. So I tried using it with an InternetOpen() handle and a NULL handle. Both failed with ERROR_INTERNET_INCORRECT_HANDLE_TYPE.

Is there a way to get this option to work? I found a reference on an MS newsgroup from 2003 that INTERNET_OPEN_TYPE_PRECONFIG is "broken". 5 years later with IE8 beta 2 and they still haven't fixed it? Or am I doing it wrong.

Edit
I wasn't quite correct. InternetConnect() always returns null if you are on "Work Offline" mode and using FTP, but it returns a valid handle if you are using Http. However, it still doesn't work even with a request handle.

If I am set to "Work Offline" and I call

BOOL a = TRUE;
::InternetSetOption(hData, INTERNET_OPTION_IGNORE_OFFLINE, &a, sizeof(BOOL));

on the handle from

HINTERNET hData = HttpOpenRequest(hInternet, L"POST", path, NULL, NULL, NULL, flags, 0 );

the InternetSetOption() call succeeds.
However, the call to HttpSendRequest() still fails with error code 2 (file not found), same as it does if I don't set the option.
Same thing if I call

::InternetSetOption(hData, INTERNET_OPTION_IGNORE_OFFLINE, 0, 0);
hexacyanide
  • 88,222
  • 31
  • 159
  • 162
mhenry1384
  • 7,538
  • 5
  • 55
  • 74

2 Answers2

1

I checked use of INTERNET_OPTION_IGNORE_OFFLINE with the IE 9 version of WinInet and it does seem to work.

Make sure you call InternetSetOption before you call HttpOpenRequest and pass in the hInternet handle instead. The option must be set before the request actually gets sent to the server. HttpOpenRequest

+++ Rick ---

Nix
  • 57,072
  • 29
  • 149
  • 198
Rick Strahl
  • 17,302
  • 14
  • 89
  • 134
0

Did you tried GET instead of POST which sends additional data in headers?

For example in REST-ful API POST request is equivalent to Create, Update, Delete and GET to Read and that might break the offline mode. Just guessing...

Nix
  • 57,072
  • 29
  • 149
  • 198
michael
  • 3,250
  • 10
  • 43
  • 58