[英]Extracting StatusCode from TWebBrowser OnNavigateError in Delphi 10.3
I'm trying to get the HTTP response code in an OnNavigateError event of a TWebBrowser.我试图在 TWebBrowser 的 OnNavigateError 事件中获取 HTTP 响应代码。 The StatusCode passed to me is always -2146697211 when it should be 404. What am I missing?
传递给我的 StatusCode 始终是 -2146697211,而它应该是 404。我错过了什么? I'm using Delphi 10.3.
我正在使用 Delphi 10.3。
TWebBrowser
uses Microsoft's Internet Explorer, so information about the NavigateError
event can be found online . TWebBrowser
使用 Microsoft 的 Internet Explorer,因此可以在网上找到有关NavigateError
事件的信息。StatusCode
parameter links to "NavigateError Event Status Codes" - there you see your typical 3-digit HTTP status codes, but also additional ones. StatusCode
参数的解释链接到“NavigateError 事件状态代码” - 您可以看到典型的 3 位 HTTP 状态代码,还有其他状态代码。 Your decimal value of -2146697211
is $800C0005
in hexadecimal - both match the INET_E_RESOURCE_NOT_FOUND
constant, which again links to another page : -2146697211
的十进制值是十六进制的$800C0005
- 两者都匹配INET_E_RESOURCE_NOT_FOUND
常量,该常量再次链接到另一个页面: Why is this a separate error code and not a HTTP one?为什么这是一个单独的错误代码而不是 HTTP 错误代码? Because it happens before HTTP is performed: looking up the IP address to a hostname has failed - nobody knows which IP address the hostname you tried to browse to has.
因为它发生在 HTTP 执行之前:查找 IP 地址到主机名失败 - 没有人知道您尝试浏览的主机名具有哪个 IP 地址。 That's what the Domain Name System (DNS) is for.
这就是域名系统 (DNS)的用途。 Not being able to get in contact with a server is a different thing than being able and getting a response.
无法与服务器取得联系与能够并获得响应是不同的事情。
HTTP 404
is a reponse. HTTP 404
是一个响应。 But since you don't even got a response, hence you cannot get a HTTP status code.但是由于您甚至没有得到响应,因此您无法获得 HTTP 状态码。
Long story short: host not found (instead of "HTTP 404" = host found, but not the page you're looking for ).长话短说:找不到主机(而不是“HTTP 404”=找到主机,但不是您要查找的页面)。 Try it with an address/a hostname that can be actually resolved.
尝试使用可以实际解析的地址/主机名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.