参数说明,
dwAccessType
The type of access required. The following are valid values, exactly one of which may be supplied:
INTERNET_OPEN_TYPE_PRECONFIG Preconfigured (in the registry). This access type is set as the default.
INTERNET_OPEN_TYPE_DIRECT Direct to Internet.
INTERNET_OPEN_TYPE_PROXY Through CERN proxy.
pstrProxyName
The name of the preferred CERN proxy if dwAccessType is set as INTERNET_OPEN_TYPE_PROXY. The default is NULL.
pstrProxyBypass
A pointer to a string containing an optional list of server addresses. These addresses may be bypassed when using proxy access. If a NULL value is supplied, the bypass list will be read from the registry. This parameter is meaningful only if dwAccessType is set to INTERNET_OPEN_TYPE_PROXY
pstrProxyName和pstrProxyBypass的意思看不明白。
dwAccessType 用INTERNET_OPEN_TYPE_PRECONFIG 读注册表的代理,
但是这个代理要用户名、密码验证的,怎么办?
(我用ccproxy设2级代理,再把注册表改成127.0.0.1可以用,我还是想知道直接的办法,免得改来改去)
用INTERNET_OPEN_TYPE_PROXY 的时候,pstrProxyName和pstrProxyBypass的值用什么?
10 个解决方案
#1
帮你顶一下了
#2
up
#3
要想实现代理,用这个也可以
typedef enum
{
SUCCESS,
BAD_URL,
BAD_FILENAME,
LOCATION_MOVED,
UNKNOWN_ERROR,
ALREADY_EXISTS,
TIMEOUT,
} RESULTS;
HINTERNET m_hSession;
//别忘在程序里project的setting里装入wininet.lib
// 初始化一个新的WinInet 会话,bUseProxy用来放入是否有代理,strProxyName代理服务器名
CInet::RESULTS CInet::OpenSession(BOOL bUseProxy, CString& strProxyName)
{
CInet::RESULTS ret;
// 打开 //:?表示一个如果关系既是不是用代理打开
m_hSession = ::InternetOpen("SiteSnagger",
bUseProxy?INTERNET_OPEN_TYPE_PROXY:INTERNET_OPEN_TYPE_PRECONFIG,
bUseProxy?(LPCTSTR)strProxyName:(LPCTSTR)NULL,
NULL,0);
// 是否成功
if(m_hSession != NULL)
{
DWORD dwTimeout = 4000;
::InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT,
&dwTimeout,sizeof(dwTimeout));
ret = SUCCESS;
}
else ret = BAD_URL;
return(ret);
}
typedef enum
{
SUCCESS,
BAD_URL,
BAD_FILENAME,
LOCATION_MOVED,
UNKNOWN_ERROR,
ALREADY_EXISTS,
TIMEOUT,
} RESULTS;
HINTERNET m_hSession;
//别忘在程序里project的setting里装入wininet.lib
// 初始化一个新的WinInet 会话,bUseProxy用来放入是否有代理,strProxyName代理服务器名
CInet::RESULTS CInet::OpenSession(BOOL bUseProxy, CString& strProxyName)
{
CInet::RESULTS ret;
// 打开 //:?表示一个如果关系既是不是用代理打开
m_hSession = ::InternetOpen("SiteSnagger",
bUseProxy?INTERNET_OPEN_TYPE_PROXY:INTERNET_OPEN_TYPE_PRECONFIG,
bUseProxy?(LPCTSTR)strProxyName:(LPCTSTR)NULL,
NULL,0);
// 是否成功
if(m_hSession != NULL)
{
DWORD dwTimeout = 4000;
::InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT,
&dwTimeout,sizeof(dwTimeout));
ret = SUCCESS;
}
else ret = BAD_URL;
return(ret);
}
#4
我也曾经看了一阵子,后来没时间放下了。
共同学习。
共同学习。
#5
to jongin,
strProxyName代理服务器名是什么? 是ip地址吗?
用户名和密码怎么办?
strProxyName代理服务器名是什么? 是ip地址吗?
用户名和密码怎么办?
#6
???
#7
谁来救我!!!!!!
#8
遇到相同问题,郁闷中啊
#9
遇到相同问题,郁闷中啊
#10
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;
}
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;
}
#1
帮你顶一下了
#2
up
#3
要想实现代理,用这个也可以
typedef enum
{
SUCCESS,
BAD_URL,
BAD_FILENAME,
LOCATION_MOVED,
UNKNOWN_ERROR,
ALREADY_EXISTS,
TIMEOUT,
} RESULTS;
HINTERNET m_hSession;
//别忘在程序里project的setting里装入wininet.lib
// 初始化一个新的WinInet 会话,bUseProxy用来放入是否有代理,strProxyName代理服务器名
CInet::RESULTS CInet::OpenSession(BOOL bUseProxy, CString& strProxyName)
{
CInet::RESULTS ret;
// 打开 //:?表示一个如果关系既是不是用代理打开
m_hSession = ::InternetOpen("SiteSnagger",
bUseProxy?INTERNET_OPEN_TYPE_PROXY:INTERNET_OPEN_TYPE_PRECONFIG,
bUseProxy?(LPCTSTR)strProxyName:(LPCTSTR)NULL,
NULL,0);
// 是否成功
if(m_hSession != NULL)
{
DWORD dwTimeout = 4000;
::InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT,
&dwTimeout,sizeof(dwTimeout));
ret = SUCCESS;
}
else ret = BAD_URL;
return(ret);
}
typedef enum
{
SUCCESS,
BAD_URL,
BAD_FILENAME,
LOCATION_MOVED,
UNKNOWN_ERROR,
ALREADY_EXISTS,
TIMEOUT,
} RESULTS;
HINTERNET m_hSession;
//别忘在程序里project的setting里装入wininet.lib
// 初始化一个新的WinInet 会话,bUseProxy用来放入是否有代理,strProxyName代理服务器名
CInet::RESULTS CInet::OpenSession(BOOL bUseProxy, CString& strProxyName)
{
CInet::RESULTS ret;
// 打开 //:?表示一个如果关系既是不是用代理打开
m_hSession = ::InternetOpen("SiteSnagger",
bUseProxy?INTERNET_OPEN_TYPE_PROXY:INTERNET_OPEN_TYPE_PRECONFIG,
bUseProxy?(LPCTSTR)strProxyName:(LPCTSTR)NULL,
NULL,0);
// 是否成功
if(m_hSession != NULL)
{
DWORD dwTimeout = 4000;
::InternetSetOption(m_hSession,INTERNET_OPTION_CONNECT_TIMEOUT,
&dwTimeout,sizeof(dwTimeout));
ret = SUCCESS;
}
else ret = BAD_URL;
return(ret);
}
#4
我也曾经看了一阵子,后来没时间放下了。
共同学习。
共同学习。
#5
to jongin,
strProxyName代理服务器名是什么? 是ip地址吗?
用户名和密码怎么办?
strProxyName代理服务器名是什么? 是ip地址吗?
用户名和密码怎么办?
#6
???
#7
谁来救我!!!!!!
#8
遇到相同问题,郁闷中啊
#9
遇到相同问题,郁闷中啊
#10
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;
}
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;
}