为什么InternetOpenURL会报错2(系统找不到指定的文件)?
我们产品中的互联网访问代码适用于 99.99% 的人。然而,对于他们中的一些人来说,这根本不起作用。我们一直在添加一些跟踪代码来尝试找出问题所在,结果发现 InternetOpenURL 正在报告错误 2 - “系统找不到指定的文件” - 来自此函数调用:
options = INTERNET_FLAG_RAW_DATA | INTERNET_FLAG_RESYNCHRONIZE;
handle = InternetOpenUrl(internet,url,NULL,0,options,0);
(internet 是句柄到使用 InternetOpen 打开的互联网连接,url 是存在于我们的 Web 服务器上的简单文本文件的 URL。)
我们测试了两个不同的网站,一个是 http,一个是 https,它们位于完全不同的位置(不同的域、服务器 )托管在地理上分开),他们都为这个人和其他一些人给出了相同的错误。 99% 的人,包括我们自己,都可以毫无问题地访问它们。不仅如此,受影响的人可以在网络浏览器中毫无问题地访问相同的 URL。
这里到底发生了什么? :(
编辑:幸运的是,我们发现了问题所在!事实证明,有些人在他们的互联网选项中选中了“为 LAN 使用代理服务器”复选框,而没有实际指定我们试图使用不存在的代理服务器详细信息,当然,
我仍然需要为此研究一个编程解决方案,但每个报告问题的人都可以通过此解决方案解决问题:
- 打开 Internet Explorer
- 转到“工具 -> Internet 选项”
- ,单击“连接”选项卡,
- 单击它。
- 在“代理服务器”字段下 ”
- 单击“确定
,重新启动 Windows,然后再次尝试通过该产品访问互联网。我不知道为什么这么多人选中了该框,但没有指定代理服务器,但显然这是需要执行的操作。修复它。
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:
- Open Internet Explorer
- Go to 'Tools -> Internet Options'
- Click the 'Connections' tab.
- There should be a button labeled 'LAN Settings' near the bottom. Click it.
- Under the 'Proxy Server' field, uncheck 'Use a proxy server for your LAN'
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
GetLastError()
可能不是找出问题所在的最佳方法。来自文档:GetLastError()
is probably not the best way to find out what went wrong. From the docs:鉴于此信息,我猜测这些用户有一个防火墙(或某种类型的安全软件),它已连接 wininet 并干扰您的呼叫。或者,他们可能感染了恶意软件。
Given this info, I would guess these users have a firewall (or some type of security software) that has hooked wininet and is interfering with your call. Alternatively, they may have malware infestation.
解决方案可能就像打开 Internet Explorer 一样简单。我从不使用浏览器,但 Windows 更新中断了对 InternetOpenUrl 的调用。
打开 IE 将设置选项,以便读取代理信息将再次起作用。请注意,在 InternetOpen() 中使用 INTERNET_OPEN_TYPE_PRECONFIG 时,这一点很重要。
最初我只在设置 INTERNET_FLAG_RELOAD 时看到问题,但很快一切都降级了,因此普通的连接也失败了。
tl;dr 打开 IE,让它加持你的系统
The solution may be as simple as opening Internet Explorer. I never use the browser, but a windows update broke calls to InternetOpenUrl.
Opening IE will setup the options so that reading proxy information will work again. Note that this is important when using INTERNET_OPEN_TYPE_PRECONFIG in InternetOpen().
Initially I only saw problems when INTERNET_FLAG_RELOAD was set, but soon everything degraded so that plain vanilla connections failed too.
tl;dr Open IE so it can bless your system
这些用户是否使用代理?如果他们在 IE 中设置了代理,则可能会获取信息并导致您的错误。
另外,我同意休的观点。有时 GetLastError() 可能会产生误导。如果您想使用它,您应该确保在调用之前设置了 SetLastError(0),否则您可能会收到由先前的某个方法调用设置的错误代码。
Are these users using a proxy? If they have a proxy set in IE, it is possible that information is being picked up and is causing your errors.
Also, I agree with Hugh. Sometimes GetLastError() can be misleading. If you want to use this, you should make sure that you SetLastError(0) before you make your call otherwise you could be getting an error code set by some previous method call.
尝试如下操作:
出现错误时,挂钩 SetLastError 函数(通过使用热补丁手动或使用 MS Detours 或其他方式),然后再次调用 InternetOpenUrl。
在挂钩函数中,如果 SetLastError 参数不为零,则进行小型转储。您将看到设置该错误的位置。
Try something like the following:
On error, hook SetLastError function (manually by using hot-patch, or by using MS Detours or something other), and call InternetOpenUrl again.
In hooking function, if SetLastError argument in't zero, make a minidump. You will get a place where that error is set.