Windows xp sp3 + ie6 Environment
How do I set a proxy server that requires a user name and password when downloading a file in CInternetSession?
If ie8 is installed, CInternetSession automatically uses the settings of ie and the creden saved by the user. The program is completely transparent, but in ie6, the same program has different behaviors, how to explicitly set the proxy server and user name password?
The following is the code that I cannot work at present. This Code does not need to have SetOption () Actions in ie8 environment to automatically work normally.
How can I configure proxy servers? BOOL GetHttpFile (maid, maid)
{
// Obtain the remote update file through http.
Char buf [65536];
CString sTemp;
CInternetSession sess;
Char * sProxyServer = _ T ("http: // 192.168.1.9: 8080 ");
Char * sProxyUserName = _ T ("bejlife \ username ");
Char * sProxyPassword = _ T ("Password ");
INTERNET_PROXY_INFO proxyinfo;
Proxyinfo. dwAccessType = INTERNET_OPEN_TYPE_PROXY;
Proxyinfo. lpszProxy = sProxyServer;
Proxyinfo. lpszProxyBypass = NULL;
Bool B = sess. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & proxyinfo, sizeof (INTERNET_PROXY_INFO), 0 );
CHttpFile * fileGet;
Try
{
FileGet = (CHttpFile *) sess. OpenURL (psUrl); //, 1, INTERNET_FLAG_TRANSFER_BINARY );
If (! FileGet)
{
Sess. Close ();
SErrMg = "remote file cannot be opened! ";
Return FALSE;
}
FileGet-> SetOption (INTERNET_OPTION_PROXY_USERNAME, (LPVOID) sProxyUserName, lstrlen (sProxyUserName) + 1, 0 );
FileGet-> SetOption (INTERNET_OPTION_PROXY_PASSWORD, (LPVOID) sProxyPassword, lstrlen (sProxyPassword) + 1, 0 );
}
Catch (CException * e)
{
FileGet = NULL;
}
If (! FileGet)
{
Sess. Close ();
SErrMg = "Remote File not found! ";
Return FALSE;
}
Int iBuffLen;
DWORD dwStatus;
DWORD dwBuffLen = sizeof (dwStatus );
BOOL bSuccess = fileGet-> QueryInfo (HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, & dwStatus, & dwBuffLen );
If (! (BSuccess & dwStatus> = 200 & dwStatus <300 ))
{
FileGet-> Close ();
Sess. Close ();
Delete fileGet;
SErrMg. Format ("An error occurred while opening the remote file. Error code: % d", dwStatus );
Return FALSE;
}
CFile fileWrite;
If (! FileWrite. Open (psLocalFile, CFile: modeWrite | CFile: modeCreate ))
{
FileGet-> Close ();
Sess. Close ();
Delete fileGet;
SErrMg. Format ("An error occurred while opening the local file .");
Return FALSE;
}
IBuffLen = fileGet-> Read (void *) buf, sizeof (buf ));
While (iBuffLen! = 0)
{
FileWrite. Write (buf, iBuffLen );
IBuffLen = fileGet-> Read (void *) buf, sizeof (buf ));
}
FileWrite. Close ();
FileGet-> Close ();
Sess. Close ();
Delete fileGet;
SErrMg. Format ("Download successful ");
Return TRUE;
}