Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would InternetOpenURL report error 2 (the system cannot find the file specified)?

Tags:

winapi

wininet

The internet access code in our product works perfectly for 99.99% of people. However, for a few of them, it just doesn't work at all. We've been adding some trace code to try and figure out what the problem is, and it it turns out that InternetOpenURL is reporting error 2 - "The system cannot find the file specified" - from this function call:

options = INTERNET_FLAG_RAW_DATA | INTERNET_FLAG_RESYNCHRONIZE;
handle = InternetOpenUrl(internet,url,NULL,0,options,0);

(internet is the handle to an internet connection opened with InternetOpen, url is the URL to a simple text file that exists on our web server.)

We test two different web sites, one http and one https, which are located in totally different places (different domains, servers hosted geographically apart) and they both give the same error for this one guy and a few others. 99% of people, including ourselves, can access them with no problems at all. Not only that, the people affected can access the same URLs without a problem in their web browsers.

What on earth could be going on here? :(

EDIT: By luck, we found out what was going wrong! It turns out that some people have the "Use a Proxy Server for your LAN" checkbox checked in their internet options, without actually specifying a proxy server. We were trying to use the non-existent proxy server details, and of course running into problems doing it.

I still need to investigate a programmatic solution for this, but everyone who reports the problem has their problem solved by this solution:

  1. Open Internet Explorer
  2. Go to 'Tools -> Internet Options'
  3. Click the 'Connections' tab.
  4. There should be a button labeled 'LAN Settings' near the bottom. Click it.
  5. Under the 'Proxy Server' field, uncheck 'Use a proxy server for your LAN'
  6. Click OK to everything, restart Windows, and try accessing internet through the product again.

I have no idea why so many people have the box checked but no proxy server specified. But apparently this is what needs to be done to fix it.

like image 913
Colen Avatar asked Feb 27 '23 05:02

Colen


1 Answers

GetLastError() is probably not the best way to find out what went wrong. From the docs:

To determine why access to the service was denied, call InternetGetLastResponseInfo.

like image 200
Hugh Allen Avatar answered May 11 '23 22:05

Hugh Allen