This is an example of downloading network files using a proxy in msdn.
Cstring gehttptfile (const char * URL)
{
Cstring szcontent;
Char strproxylist [max_path], strusername [64], strpassword [64];
// In this case "proxya" is the proxy server name, and "8080" is its port
Strcpy (strproxylist, "proxya: 8080 ");
Strcpy (strusername, "myusername ");
Strcpy (strpassword, "mypassword ");
DWORD dwservicetype = afx_inet_service_http;
Cstring szserver, szobject;
Internet_port nport;
AfxParseURL (url, dwServiceType, szServer, szObject, nPort );
CInternetSession mysession;
CHttpConnection * pConnection;
CHttpFile * pHttpFile;
PConnection = mysession. GetHttpConnection (szServer,
INTERNET_FLAG_KEEP_CONNECTION,
INTERNET_INVALID_PORT_NUMBER,
NULL, NULL );
PHttpFile = pConnection-> OpenRequest ("GET", szObject,
NULL, 0, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION );
// Here for proxy
INTERNET_PROXY_INFO proxyinfo;
Proxyinfo. dwAccessType = INTERNET_OPEN_TYPE_PROXY;
Proxyinfo. lpszProxy = strProxyList;
Proxyinfo. lpszProxyBypass = NULL;
Mysession. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & proxyinfo, sizeof (INTERNET_PROXY_INFO ));
PHttpFile-> SetOption (INTERNET_OPTION_PROXY_USERNAME, strUsername, strlen (strUsername) + 1 );
PHttpFile-> SetOption (INTERNET_OPTION_PROXY_PASSWORD, strPassword, strlen (strPassword) + 1 );
PHttpFile-> SendRequest (NULL );
DWORD nFileSize = pHttpFile-> GetLength ();
LPSTR rbuf = szContent. GetBuffer (nFileSize );
Uint ubytesread = phttpfile-> Read (rbuf, nfilesize );
Szcontent. releasebuffer ();
Phttpfile-> close ();
Delete phttpfile;
Pconnection-> close ();
Delete pconnection;
Mysession. Close ();
Return szcontent;
}
Assert (m_astrproxies.getsize ()> 0 );
Cstring strproxy = m_astrproxies [m_iproxyindex];
If (strproxy. isempty ())
{
Internet_proxy_info IPI;
IPI. dwaccesstype = internet_open_type_direct;
IPI. lpszproxy = NULL;
IPI. lpszproxybypass = NULL;
Urlmksetsessionoption (internet_option_proxy, & IPI, sizeof (IPI), 0 );
}
Else
{
Internet_proxy_info IPI;
IPI. dwaccesstype = internet_open_type_proxy;
IPI. lpszproxy = strproxy;
IPI. lpszproxybypass = NULL;
Urlmksetsessionoption (internet_option_proxy, & IPI, sizeof (IPI), 0 );
}
Setoption (internet_option_proxy_username, (lpvoid) szid,: lstrlen (szid ));
Setoption (internet_option_proxy_password, (lpvoid) szpassword,: lstrlen (szpassword ));