所以我承认,我试图找到这个问题没有运气,因为我不确定要搜索什么 - 主要是因为我不确定问题是否与VB.NET或Apache有关。 / p>
短版本:从Network.DownloadFile获取404时,如果我尝试从http:// *地址加载文档并且Apache将其重定向到https,则不会捕获404 ://* 地址。相反,VB.NET将404页面下载到.png文件。
如果我尝试从https:// *加载它并且Apache不需要重定向请求,404就会被捕获。如果我尝试从http:// *加载它并且Apache不会将我重定向到https:// *,那么404就会被捕获。
我已经验证Apache在所有情况下都在提供SAME 404页面。
代码示例:
Try
'TRY to download the file using https first...
My.Computer.Network.DownloadFile(New Uri("https://" & ServerAddress & WebLogoPath & Convert.ToString(RowArray(0)) & ".png"), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\" & AppDataFolder & PCLogoPath & Convert.ToString(RowArray(0)) & ".png", "", "", False, 500, True)
Catch ex_https As Exception
'Unable to locate file or write file
'If the operation timed out...
If (ex_https.Message = "The operation has timed out") Then
'Re-TRY to download the file using http instead, as a time out error may indicate that HTTPS is not supported.
Try
My.Computer.Network.DownloadFile(New Uri("http://" & ServerAddress & WebLogoPath & Convert.ToString(RowArray(0)) & ".png"), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\" & AppDataFolder & PCLogoPath & Convert.ToString(RowArray(0)) & ".png", "", "", False, 500, True)
Catch ex_http As Exception
'Most likely, the file doesn't exist on the server. Either way, we cannot obtain the file so we need to perform the same action,
'which is handled outside of this Try block.
End Try
Else
'This is most likely a 404 error. Either way, we cannot obtain the file (and the connection is not timing out) - so
'we need to perform the same action, which is handled outside of this Try block.
End If
End Try
上面的代码是解决这个问题的解决办法;然而,由于我现在必须等待每个超时时间(500毫秒),因此效率非常低。这可能看起来不是什么大问题 - 但这完全在For循环中需要检查X文件 - 这意味着每次检查可能需要1秒才能完成。最后,如果我的循环被处理了100次 - 这可能是将近2分钟的等待时间。
如果可能的话,我想通过仅尝试从http:// *加载图像并在请求被重定向到https:// *时捕获404来将其切成两半。
更多信息:我可以标准化Apache和我的代码使用的方法。但是,这都与从2个不同服务器托管的数据相关(数据在它们之间重复)。一台服务器支持AND FORCES SSL,另一台服务器不支持。我不是在寻找一种涉及在任一服务器上更改SSL规则的解决方案。我只是在寻找一种解决方案,导致VB.NET正确报告404错误。
我强烈认为这是VB中的错误而不是Apache,但我可能错了。我只是建议,因为我可以确认Apache无论如何都在提供完全相同的文件。影响VB的唯一因素是请求是否从http:// *重定向到https:// *