# Include <afxinet. h>
# Pragma comment (Lib, "wininet. lib ")
//-----------------------------------------------------------------------------
// Webpage download
// In: the source code of the strdowntext downloaded from the strdowntext page. the URL of the strurl webpage
// Out:
// Return: True is returned for success, and false is returned for failure.
// Author: 2005-8-8 created by yangdz
// Note:
//-----------------------------------------------------------------------------
Bool downhttp (cstring & strdowntext, const char * URL)
{
Char strproxylist [max_path], strusername [64], strpassword [64];
// In this case "proxya" is the proxy server name, and "8080" is its port
Strcpy (strproxylist, "203.55.231.107: 8080"); // proxy server address
Strcpy (strusername, ""); // User Name
Strcpy (strpassword, ""); // Password
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 = strdowntext. getbuffer (nfilesize );
Uint ubytesread = phttpfile-> Read (rbuf, nfilesize );
Strdowntext. releasebuffer ();
Phttpfile-> close ();
Delete phttpfile;
Pconnection-> close ();
Delete pconnection;
Mysession. Close ();
Return true;
}