TIPS: it takes two days for the wininet proxy server in VC to solve the problem.

Source: Internet
Author: User
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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.