简体   繁体   English

从 Delphi 10.3 中的 TWebBrowser OnNavigateError 中提取 StatusCode

[英]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。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM