The information in this article applies to:
SUMMARYWinInet applications attempting to access files through a proxy that requires a login will fail unless the proxy is provided with a valid username and password. This article will explain the different options available to handle this situation. MORE INFORMATION
For the sake of clarity, error handling has been removed from most of the
code in this article. If you use any of this code in your own program,
please implement error handling appropriately. As well, anywhere you find
"...", code has been removed. Please reference the HttpDump and Tear
samples for complete implementations of WinInet coding.
A check for HTTP_STATUS_PROXY_AUTH_REQ can be added to the Tear MFC sample to check for HTTP_STATUS_PROXY_AUTH_REQ:
Both samples can successfully handle HTTP_STATUS_PROXY_AUTH_REQ by providing a user interface to collect the username and password for proxy authorization. The HttpDump sample does so with the following code:
WinInet will query hReq to determine the type of error and in the case of HTTP_STATUS_PROXY_AUTH_REQ, will present the user with the dialog box to collect the username and password for proxy authorization. MFC wraps the InternetErrorDlg call and will attempt the proxy authorization with the following code:
Unfortunately, CHttpFile::ErrorDlg is broken in the MFC that ships with Visual C++ versions prior to 6.0. For additional information on how to call InternetErrorDlg from an MFC application, please see the following article in the Microsoft Knowledge Base: Q189094 Calling CHttpFile::ErrorDlg Function Causes Errors 127 & 2The drawback of the using InternetErrorDlg is that the function call displays a user interface. In some cases, this is not desirable. There are several ways to handle HTTP_STATUS_PROXY_AUTH_REQ without displaying a user interface. By far the easiest way to do this is by using the InternetSetOption function with the flags INTERNET_OPTION_PROXY_PASSWORD and INTERNET_OPTION_PROXY_USERNAME. This option can be used only on clients that have Internet Explorer 4.0 or later loaded as the WinInet that shipped before Internet Explorer 4.0 did not implement this functionality. It will also be necessary to link with the updated WinInet.h and WinInet.lib from the Internet Client SDK or Microsoft Platform SDK. The following code illustrates how to implement this functionality with straight WinInet:
The same functionality can be accomplished in an MFC application by detecting HTTP_STATUS_PROXY_AUTH_REQ, calling CInternetSession::SetOption, then re-calling CHttpFile::SendRequest. If the client computer does not have Internet Explorer 4 installed, a good deal more work will be necessary to avoid using InternetErrorDlg. In this case, it will be necessary to Base64 encrypt the proxy username and password and add the Proxy-Authorization header as follows. In this example, "wWdkd2284lwwdj" is a Base64 encrypted user username:password combination.
A sample is available that implements a Base54 encryption algorithm. For additional information, see the following article in the Microsoft Knowledge Base: Q191239 SAMPLE: Sample Base 64 Encoding and DecodingThe format of the username and password that needs to be encrypted is "username:password" including the colon. Please reference RFC2068 - "Hypertext Transfer Protocol -- HTTP/1.1" for further details on this. MFC WinInet applications can implement the same functionality. To do so, the application should call CHttpFile::AddRequestHeaders and add the Proxy- Authorization header as above. The application should then resubmit the request with CHttpFile::SendRequest. REFERENCES
RFC 2068 / Hypertext Transfer Protocol -- HTTP/1.1
Additional query words:
Keywords : kbnokeyword kbIE400 |
Last Reviewed: April 24, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |