CodePudding user response:
CInternetSession session;CHttpFile * pFile=NULL;
INTERNET_PROXY_INFO proxyInfo;
ProxyInfo. DwAccessType=INTERNET_OPEN_TYPE_PROXY;
ProxyInfo. LpszProxy=_T (192.168.1.21: "8080");
ProxyInfo. LpszProxyBypass=NULL;
AnsiString UserName="usr";
AnsiString UserPassWord=password ";
The session. SetOption (INTERNET_OPTION_PROXY, (LPVOID) & amp; ProxyInfo, sizeof (INTERNET_OPTION_PROXY), 0);
UrlMkSetSessionOption (INTERNET_OPTION_PROXY, & amp; ProxyInfo, sizeof (proxyInfo), 0);
CHttpConnection * pConnection=session. GetHttpConnection (_T (" www.baidu.com "));
Session. SetOption (INTERNET_OPTION_PROXY_USERNAME, UserName. C_str (), dwords (UserName. The Length ()) + 1);
Session. SetOption (INTERNET_OPTION_PROXY_PASSWORD, UserPassWord c_str (), dwords (UserPassWord. The Length ()) + 1);
If (pConnection==NULL)
{
ShowMessage (" I'm sorry, connect to the server failed!" );
return;
}
WebBrowser1 - & gt; Navigate (L "http://www.baidu.com");
PConnection - & gt; Close ();
The delete pConnection;
The session. The Close ();
return;