//in this case "proxya" is the proxy server name, "8080" is its port strcpy(strProxyList, "proxya:8080"); proxya为你的代理服务器名。 你的代理服务器的IP是146.127.7.103,必须先得到服务器名。 CHttpConnection* pHTTP=sess.GetHttpConnection("146.127.7.103",dwFlags,8080,"pub","every");//INTERNET_INVALID_PORT_NUMBER 146.127.7.103应该是目的URL,而不是你的代理服务器的IP地址
to kingzai: 146.127.7.103应该是目的URL,而不是你的代理服务器的IP地址 我不能理解这话的意思. 为什么这你还是用 CHttpConnection* pHTTP=sess.GetHttpConnection("146.127.7.103",dwFlags,8080,"pub","every");//INTERNET_INVALID_PORT_NUMBERGetHttpConnection第一个参数到底是指代理服务地址还是我想下载网页的 ip地址呢?
first parameter of GetHttpConnection is target server of your url(not proxy server).
//--------------------------------------------------------------------------------
To find details about Proxy Authentication and Sever Authentication methed in MSDN,
Just search for the keyword "INTERNET_OPTION_USERNAME".
a very simple example.
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;
}
非常感谢你的指点,
但是程序运行出现
无法解析服务器名称或地址对话框
我单步运行程序在
pHttpFile->SendRequest(NULL);
出现问题我认为去掉这条语句应该没什么大问题只是一条发送请求语句吗
后来我把//pHttpFile->SendRequest(NULL);语句去掉
得到szContent里为空,
我有输入错误用户名 和密码也是
得到szContent里为空,
我又修改url地址为 http://www.csdn.net/ 等都是一样的结果.
不少问题?首先 masterz()你给的上面那段程序怎么没有代理服务器的ip地址呢?
后来我把proxyinfo.lpszProxyBypass = "146.127.7.103" kingzai()说
INTERNET_OPEN_TYPE_PROXY property in OpenRequest我就加了
CInternetSession( AfxGetAppName(), 1,INTERNET_OPEN_TYPE_PROXY,NULL,"146.127.7.103",0 );
在语句前加pHttpFile->SetOption(INTERNET_OPTION_PROXY_USERNAME, strUsername, strlen(strUsername)+1);
但是运行效果
无法解析服务器名称或地址 对话框
我单步运行程序在
pHttpFile->SendRequest(NULL);
和前面出现的问题一样.现在我很迷惘,请各位朋友一起讨论.
strcpy(strProxyList, "proxya:8080");
proxya为你的代理服务器名。
你的代理服务器的IP是146.127.7.103,必须先得到服务器名。
CHttpConnection* pHTTP=sess.GetHttpConnection("146.127.7.103",dwFlags,8080,"pub","every");//INTERNET_INVALID_PORT_NUMBER
146.127.7.103应该是目的URL,而不是你的代理服务器的IP地址
146.127.7.103应该是目的URL,而不是你的代理服务器的IP地址
我不能理解这话的意思.
为什么这你还是用
CHttpConnection* pHTTP=sess.GetHttpConnection("146.127.7.103",dwFlags,8080,"pub","every");//INTERNET_INVALID_PORT_NUMBERGetHttpConnection第一个参数到底是指代理服务地址还是我想下载网页的
ip地址呢?