急!!!高分请教,InternetOpen怎么使用socks代理。

huang_yi_cn 2005-05-07 04:35:52
如题,谢谢!
...全文
736 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jerry 2005-05-09
  • 打赏
  • 举报
回复
我慢慢看看... 我开一帖给你分.

楼主去接分:
http://community.csdn.net/Expert/topic/3990/3990681.xml?temp=.7436945
fisker0303 2005-05-08
  • 打赏
  • 举报
回复
恩,学习。
huang_yi_cn 2005-05-08
  • 打赏
  • 举报
回复
我找到答案了, 来此跟大家分享一下吧:
1. 相关函数:
HINTERNET WINAPI InternetOpen(
LPCTSTR lpszAgent,
DWORD dwAccessType,
LPCTSTR lpszProxy,
LPCTSTR lpszProxyBypass,
DWORD dwFlags);

BOOL WINAPI InternetSetOption(
HINTERNET hInternet,
DWORD dwOption,
LPVOID lpBuffer,
DWORD dwBufferLength);

2. 相关结构
typedef struct {
DWORD dwAccessType;
LPCTSTR lpszProxy;
LPCTSTR lpszProxyBypass;
} INTERNET_PROXY_INFO, *LPINTERNET_PROXY_INFO;

3. 使用代理服务器
(1)请将dwAccessType设置成INTERNET_OPEN_TYPE_PROXY
(2)设置lpszProxy
(a)代理的格式必须为:[<protocol>=][<scheme>://]<proxy>[:<port>].
(b)其中protocol, scheme://, :port是可选项, 如果忽略这三者, 则它们默认分别为
HTTP, HTTP://, :80. 即默认为HTTP代理.
(c)多个代理必须使用" "(空格)隔开
(d)各种常用代理的使用见如下:
HTTP:
HTTP=HTTP://proxyserver:port
FTP:
FTP:FTP://proxyserver:port
GOPHER
GOPHER=HTTP://proxyserver:port
SOCKS=proxyserver:port
其中前三种都可以在msdn中找到, 但第四种我可是找了N多地方才好不容易找到了. 另外要注意, msdn中明确说明只有安装了IE才能使用SOCKS代理.
louifox 2005-05-08
  • 打赏
  • 举报
回复
学习
huang_yi_cn 2005-05-08
  • 打赏
  • 举报
回复
别忘了给分哟, 呵呵呵
huang_yi_cn 2005-05-08
  • 打赏
  • 举报
回复
详细说明请见msdn:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/handling_authentication.asp
huang_yi_cn 2005-05-08
  • 打赏
  • 举报
回复
这段代码就是设置代理的用户名和密码的呀, 其中INTERNET_OPTION_USERNAME设置代理服务器的用户名, INTERNET_OPTION_PASSWORD设置相应的密码.
删繁就简, 如果只是纯粹的设置用户名和密码, 只需要下面的代码就可以了.
InternetSetOption(hResourceHandle, INTERNET_OPTION_USERNAME,
strUsername, cchUserLength+1);
InternetSetOption(hResourceHandle, INTERNET_OPTION_PASSWORD,
strPassword, cchPasswordLength+1);

其中strUsername设置用户名, strPassword指定密码.
jerry 2005-05-08
  • 打赏
  • 举报
回复
这段代码好象跟代理没什么关系呀!
huang_yi_cn 2005-05-08
  • 打赏
  • 举报
回复
The following example code shows how authentication could be handled using InternetSetOption.


HINTERNET hOpenHandle, hResourceHandle;
DWORD dwError, dwStatus;
DWORD dwStatusSize = sizeof(dwStatus);
char strUsername[64], strPassword[64];

hOpenHandle = InternetOpen("Example",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
hConnectHandle = InternetConnect(hOpenHandle,
"www.server.com",
INTERNET_INVALID_PORT_NUMBER,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,0);

hResourceHandle = HttpOpenRequest(hConnectHandle, "GET",
"/premium/default.htm",
NULL, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION,
0);

resend:

HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0);

HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER |
HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL);

switch (dwStatus)
{
case HTTP_STATUS_PROXY_AUTH_REQ: // Proxy Authentication Required
// Insert code to set strUsername and strPassword.

// cchUserLength is the length of strUsername and
// cchPasswordLength is the length of strPassword.
DWORD cchUserLength, cchPasswordLength;

// Insert code to safely determine cchUserLength and
// cchPasswordLength. Insert appropriate error handling code.
InternetSetOption(hResourceHandle,
INTERNET_OPTION_PROXY_USERNAME,
strUsername,
cchUserLength+1);

InternetSetOption(hResourceHandle,
INTERNET_OPTION_PROXY_PASSWORD,
strPassword,
cchPasswordLength+1);
goto resend;
break;

case HTTP_STATUS_DENIED: // Server Authentication Required.
// Insert code to set strUsername and strPassword.

// cchUserLength is the length of strUsername and
// cchPasswordLength is the length of strPassword.
DWORD cchUserLength, cchPasswordLength;

// Insert code to safely determine cchUserLength and
// cchPasswordLength. Insert error handling code as
// appropriate.
InternetSetOption(hResourceHandle, INTERNET_OPTION_USERNAME,
strUsername, cchUserLength+1);
InternetSetOption(hResourceHandle, INTERNET_OPTION_PASSWORD,
strPassword, cchPasswordLength+1);
goto resend;
break;
}

// Insert code to read the data from the hResourceHandle
// at this point.



给分, 哈哈
jerry 2005-05-08
  • 打赏
  • 举报
回复
楼主,怎么区分SOCK4/SOCK5代理?
SOCK5代理一般还需要身份认证的.
我分很多,多给你分.

能说详细一点吗?
jerry 2005-05-08
  • 打赏
  • 举报
回复
收藏!
jerry 2005-05-07
  • 打赏
  • 举报
回复
这个我也想知道!~
hai_feng 2005-05-07
  • 打赏
  • 举报
回复
up

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧