解决需要代理身份验证的问题
我编写了一个 Delphi 应用程序,需要与远程 Web 服务器通信。我将 INTERNET_OPEN_TYPE_PRECONFIG 标志传递到 InternetOpen 函数中,以初始化我的应用程序对 WinINet 函数的使用,并通过这样做,我的应用程序从注册表中检索用户的 Internet 配置。
NetHandle := InternetOpen('WebTool', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
try
hConnect := InternetConnect(NetHandle, PChar(ServerName), ServerPort,
nil, nil, INTERNET_SERVICE_HTTP, 0, 1);
if Assigned(hConnect) then
begin
try
// Open the request
hRequest := HttpOpenRequest(hConnect, PChar('POST'),
PChar(ServerScript), nil, nil, nil,
HTTPOpenRequestFlags, 0);
if Assigned(hRequest) then
begin
也许由于我的无知,我相信这可以使用用户的特定互联网设置(无论是直接连接还是通过代理)与远程 Web 服务器进行通信。它当然可以通过我公司的代理服务器运行。
然而,我现在遇到了一位客户,上述情况不允许他访问。他看到的是“需要代理身份验证”(HTTP 状态代码 407)。
这是我的应用程序应该处理的事情吗(例如提供一个表单来输入代理身份验证详细信息并通过我的 HTTP 请求传递它们)?有没有办法自动获取这些信息?
或者这仅仅是客户 IT 部门可以轻松解决的配置问题?
任何指示将不胜感激。
I've written a Delphi application which requires communication with a remote web server. I pass INTERNET_OPEN_TYPE_PRECONFIG flag into the InternetOpen function to initialise my app's use of the WinINet functions and by doing so my app to retrieve the user's Internet configuration from the registry.
NetHandle := InternetOpen('WebTool', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then
begin
try
hConnect := InternetConnect(NetHandle, PChar(ServerName), ServerPort,
nil, nil, INTERNET_SERVICE_HTTP, 0, 1);
if Assigned(hConnect) then
begin
try
// Open the request
hRequest := HttpOpenRequest(hConnect, PChar('POST'),
PChar(ServerScript), nil, nil, nil,
HTTPOpenRequestFlags, 0);
if Assigned(hRequest) then
begin
Perhaps due to my ignorance, I believed this enabled communication with the remote web server using the user's particular Internet settings whether direct connection or via a proxy. It certainly works via my company's proxy server.
However, I've now encountered one customer for whom the above does not allow him access. He sees a "Proxy Authentication Required" (HTTP status code 407) instead.
Is this something that my app should be handling (e.g. provide a form to enter proxy authentication details and pass them with my HTTP requests)? Is there a way of picking up this information automatically?
Or is this simply down to a configuration issue that the customer's IT department can easily resolve?
Any pointers would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要处理身份验证,具体取决于代理支持的身份验证方法(它将在 407 响应中告诉您)。请参阅 http://msdn.microsoft.com/en-us /library/aa384220(VS.85).aspx
You may need to handle authentication, depending on what auth methods the proxy supports (it will tell you in the 407 response). See http://msdn.microsoft.com/en-us/library/aa384220(VS.85).aspx