http - HttpSendRequest returns failure / error code 2 when Work Offline enabled -


i'm trying use use wininet make http requests , httpsendrequest() returns failure while other applications , browsers seem have internet access.
when check getlasterror() returns 2. isn't 1 of standard wininet error codes, win32 error_file_not_found.

this failing multiple pieces of code here's 1 test with:

'split url component parts urlinfo = spliturl(url) authflags = iif(urlinfo.lpszusername = "" , urlinfo.lpszpassword = "", internet_flag_no_auth, 0)  'create connection server sessionhandle = internetconnect(inethandle, urlinfo.lpszhostname, urlinfo.nport, urlinfo.lpszusername, urlinfo.lpszpassword, urlinfo.nscheme, authflags, 0) if sessionhandle = 0   err.raise httperrorinitsession, , "failed initialise http session: " & cstr(err.lastdllerror) end if  'create request resource requesthandle = httpopenrequest(sessionhandle, iif(postdata = "", "get", "post"), urlinfo.lpszurlpath & urlinfo.lpszextrainfo, "http/1.1", vbnullstring, vbnullstring, internet_flag_reload or internet_flag_no_cache_write or authflags, 0) if requesthandle = 0   err.raise httperrorinitrequest, , "failed initialise http request: " & cstr(err.lastdllerror) end if  'send request requestsent = (httpsendrequest(requesthandle, sendheaders, len(sendheaders), vbnullstring, 0) = 1) 'wait "success" message if not requestsent   err.raise httperrornohost, , "failed connect http server: " & cstr(err.lastdllerror) end if 

i've tried running packet capture , looking @ network traffic when fails , doesn't try make connection.

what's going on here , why seem occur randomly?

httpsendrequest() fail error code of 2 (error_file_not_found) when windows/internet explorer set "work offline" , resource not in offline cache.

this doesn't seem effect .net based http clients or other web browsers firefox or chrome making not immediatly obvious if internet explorer not primary or default browser.

you can go "online" opening internet explorer, going file menu (pressing alt if it's not visible), , unticking "work offline". after this, programmatic attempts use wininet work correctly.

note windows/internet explorer can state accidentally if set dial up/vpn connections testing or occasional use , not set "never dial connection"


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -