如何通过代理服务器取页面代码

adson 2002-07-22 11:36:05
做了一个程序,需要取指定地址网页的HTML代码,
而不是直接显示出来,有点像webzip的感觉,
但现在需要支持代理,请问在VC中如何实现
在程序中支持代理服务器。

请说具体一点好吗,MSDN中找不到,多谢!
回答看明白了就给分。
...全文
24 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
adson 2002-07-22
多谢二位,我已经给分了。
回复
iamQQ 2002-07-22
http://www.csdn.net/expert/topic/772/772055.xml?temp=.3672296
回复
iamQQ 2002-07-22
也就是说,你要做个客户端的代理程序。或者说你要作一个支持客户代理的程序
回复
masterz 2002-07-22
//Download http file through proxy
//--------------------------------------------------------------------------------
We can find details about Proxy Authentication and Sever Authentication methed in MSDN.
Just search for the keyword "INTERNET_OPTION_USERNAME".
Here I give a very simple example. It works in my project.
CString GeHttptFile(const char *url)
{
CString szContent;
char strProxyList[MAX_PATH], strUsername[64], strPassword[64];
//in this case "proxya" is the proxy server name, "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;
}
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告