http://www.csdn.net/Expert/topic/483/483134.shtm

解决方案 »

  1.   

    我还可能下ftp上的东西,也行吗?
      

  2.   

    我还可能下ftp上的东西,也行吗?
      

  3.   

    HOWTO: Programmatically Query and Set Proxy Settings Under Internet Explorer Q226473
    --------------------------------------------------------------------------------
    The information in this article applies to:Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 5.0--------------------------------------------------------------------------------
    SUMMARY
    The article explains the steps neccessary to programmatically query and set the proxy setting information for Internet Explorer.Under Internet Explorer 4.x and earlier, the InternetSetOption and InternetQueryOption APIs are used with the INTERNET_OPTION_PROXY flag. While this option will still work under Internet Explorer 5, multiple connection options have been introduced in the new version. Given this, the INTERNET_OPTION_PROXY flag will return only the "static" proxy server setting. The static option is the proxy server information stored under the HKEY_CURRENT_USER hive much the same way it was under Internet Explorer 4.0NOTE: INTERNET_OPTION_PROXY does not permanently change the settings. It does this for the current process only when a NULL handle is used. However, it can also change the settings on a per session basis if a valid session handle is sent in (session handles are obtained using the InternetOpen() API). If under Internet Explorer 5, you specified a different connection option (such as a dial up connection) as the default, it possible that the proxy information you obtain using the INTERNET_OPTION_PROXY flag may be incorrect for the current Internet Explorer session. For this reason, under Internet Explorer 5, it is recommended that the INTERNET_OPTION_PER_CONNECTION_OPTION be used instead.NOTE: INTERNET_OPTION_PER_CONNECTION_OPTION causes the settings to be changed on a system-wide basis when a NULL handle is used. Or to set the settings on a per session basis, a valid session handle can be used. MORE INFORMATION
    Under Internet Explorer 4.x, a typical mechanism to query the proxy information would look something like this:unsigned long        nSize = 4096;
    char                 szBuf[4096] = { 0 };
    INTERNET_PROXY_INFO* pInfo = (INTERNET_PROXY_INFO*)szBuf;if(!InternetQueryOption(NULL, INTERNET_OPTION_PROXY, pInfo, &nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError()); 
    Under Internet Explorer 5, the recommended way is to use code similar to below: INTERNET_PER_CONN_OPTION_LIST    List;
    INTERNET_PER_CONN_OPTION         Option[5];
    unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);Option[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
    Option[1].dwOption = INTERNET_PER_CONN_AUTODISCOVERY_FLAGS;
    Option[2].dwOption = INTERNET_PER_CONN_FLAGS;
    Option[3].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
    Option[4].dwOption = INTERNET_PER_CONN_PROXY_SERVER;List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
    List.pszConnection = NULL;
    List.dwOptionCount = 5;
    List.dwOptionError = 0;
    List.pOptions = Option;if(!InternetQueryOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, &nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError());
       if(Option[0].Value.pszValue != NULL)
       printf("%s\n", Option[0].Value.pszValue);if((Option[2].Value.dwValue & PROXY_TYPE_AUTO_PROXY_URL) == PROXY_TYPE_AUTO_PROXY_URL)
      printf("PROXY_TYPE_AUTO_PROXY_URL\n");if((Option[2].Value.dwValue & PROXY_TYPE_AUTO_DETECT) == PROXY_TYPE_AUTO_DETECT)
       printf("PROXY_TYPE_AUTO_DETECT\n");INTERNET_VERSION_INFO      Version;
    nSize = sizeof(INTERNET_VERSION_INFO);InternetQueryOption(NULL, INTERNET_OPTION_VERSION, &Version, &nSize);if(Option[0].Value.pszValue != NULL)
       GlobalFree(Option[0].Value.pszValue);if(Option[3].Value.pszValue != NULL)
       GlobalFree(Option[3].Value.pszValue);if(Option[4].Value.pszValue != NULL)
       GlobalFree(Option[4].Value.pszValue); 
    The code above specifies the connection by setting the pszConnection string in the INTERNET_PER_CONN_OPTION_LIST structure. By setting this string to NULL, the configuration information will be retrieved for the default (or LAN) settings.The first option (Option[0] INTERNET_PER_CONN_AUTOCONFIG_URL) will return the URL specified for auto configuration of the proxy server. The second option (Option[1] INTERNET_PER_CONN_AUTODISCOVERY_FLAG) will detect whether the auto detect option is enabled or not for the connection specified. The third option will determine what combination of flags have been set for this particular connection. The last two options correspond to the same information as retrieved whe INTERNET_OPTION_PROXY was used in Internet Explorer 4.x.As you also see, the options that can potentially return string values are freed using GlobalFree(). This is because the string buffers are allocated for you by the WININET library, and it's up to the programmer to free up the buffer after using it.To obtain information for a different connection, simply change the List.pszConnection string to point to the Dial-Up setting entry you're interested it.Similarly, to set proxy information, you would use the same technique but with InternetSetOption() instead, for example:
    INTERNET_PER_CONN_OPTION_LIST    List;
    INTERNET_PER_CONN_OPTION         Option[1];
    unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);Option[0].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
    Option[0].Value.pszValue = "http://myproxy:8080";List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
    List.pszConnection = NULL;
    List.dwOptionCount = 1;
    List.dwOptionError = 0;
    List.pOptions = Option;if(!InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError());
     
    Once again, the above sample will change the default (or LAN) settings (List.pszConnection == NULL). In the sample, the "static" proxy server information is changed to "http://myproxy" at port 8080. Similarly you can also change the auto configuration URL:INTERNET_PER_CONN_OPTION_LIST    List;
    INTERNET_PER_CONN_OPTION         Option[2];
    unsigned long                    nSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);Option[0].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
    Option[0].Value.pszValue = "http://myserver/get_proxy_info.dll";
    Option[1].dwOption = INTERNET_PER_CONN_FLAGS;
    Option[1].Value.dwValue = PROXY_TYPE_AUTO_PROXY_URL;List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST);
    List.pszConnection = NULL;
    List.dwOptionCount = 2;
    List.dwOptionError = 0;
    List.pOptions = Option;if(!InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &List, nSize))
       printf("InternetQueryOption failed! (%d)\n", GetLastError());
     
    In the sample above (again the default or LAN setting), you have to specify the auto proxy configuration URL and set the option flag to enable the auto proxy configuration. REFERENCES
    MSDN WinInet API Documentation, April 1999 Additional query words: Keywords : kbIE400 kbie401 kbie401sp1 kbie500 
    Issue type : kbhowto 
    Technology : kbIEsearch kbAudDeveloper kbSDKIESearch kbSDKIE400 kbSDKIE401 kbSDKIE401SP1 
    Last Reviewed: May 5, 1999
    © 2001 Microsoft Corporation. All rights reserved. Terms of Use.
     --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources. 
      

  4.   

    HOWTO: How to Handle Proxy Authorization with WinInet Q195650
    --------------------------------------------------------------------------------
    The information in this article applies to:Microsoft Internet Explorer (Programming) versions 3.0, 4.0--------------------------------------------------------------------------------
    SUMMARY
    WinInet 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. The following code snippet was taken from the HttpDump sample. It illustrates how to capture a proxy authorization request (HTTP_STATUS_PROXY_AUTH_REQ):
    HttpSendRequest (hReq, NULL, 0, NULL, 0);
    HttpQueryInfo (hReq, HTTP_QUERY_STATUS_CODE |
          HTTP_QUERY_FLAG_NUMBER, &dwCode, &dwSize, NULL);if (dwCode == HTTP_STATUS_PROXY_AUTH_REQ) A check for HTTP_STATUS_PROXY_AUTH_REQ can be added to the Tear MFC sample to check for HTTP_STATUS_PROXY_AUTH_REQ: 
    pFile->SendRequest();
    pFile->QueryInfoStatusCode(dwRet);if (dwRet == 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: 
    if ( InternetErrorDlg (GetDesktopWindow(),
          hReq, ERROR_INTERNET_INCORRECT_PASSWORD,
          FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
          FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
          FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
          NULL) == ERROR_INTERNET_FORCE_RETRY)
                goto again; 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: 
    dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,
          FLAGS_ERROR_UI_FLAGS_GENERATE_DATA |
                FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL); 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 & 2 
    The 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: 
    if (dwCode == HTTP_STATUS_PROXY_AUTH_REQ)
    {
       // read the data off the request handle and setup buffer see
       // handler HttpDump handler for HTTP_STATUS_DENIED for details
       ...   InternetSetOption (hConnect, INTERNET_OPTION_PROXY_USERNAME,
             (LPVOID) szUser, lstrlen (szUser);
       InternetSetOption (hConnect, INTERNET_OPTION_PROXY_PASSWORD,
             (LPVOID) szPass, lstrlen (szPass);   // calls HttpSendRequest again - see HttpDump
       goto again; 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. 
    char* rangeHeader = "Proxy-Authorization: Basic wWdkd2284lssdj\r\n";
    DWORD dwBuffSize = strlen(rangeHeader);if (dwCode == HTTP_STATUS_PROXY_AUTH_REQ)
    {
       HttpAddRequestHeaders(hReq, rangeHeader, dwBuffSize,
               HTTP_ADDREQ_FLAG_ADD );   // calls HttpSendRequest again - see HttpDump
       goto again; 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 Decoding 
    The 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 (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Robert Duke, Microsoft Corporation Additional query words: Keywords : kbnokeyword kbIE400 
    Issue type : kbhowto 
    Technology : kbIEsearch kbAudDeveloper kbSDKIESearch kbSDKIE300 kbSDKIE400 
    Last Reviewed: April 26, 1999
    © 2001 Microsoft Corporation. All rights reserved. Terms of Use.
     --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.