Http proxy,帮我看看是怎么回事呀

xdljf 2004-07-26 10:11:23
Proxy Server返回给我的信息:

HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. )
Via:1.1 PROXY3
Proxy-Authenticate: NTLM
Proxy-Authenticate: Kerberos
Proxy-Authenticate: Negotiate
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 3767

能不能帮我看看是怎么回事
我的部分源代码
// Use inet_addr() to determine if we're dealing with a name or an address
IN_ADDR iaProxy;
LPHOSTENT lpProxyEntry;
iaProxy.s_addr = inet_addr(lpszProxyAddress);
if (iaProxy.s_addr == INADDR_NONE)
{
// Wasn't an IP address string, assume it is a name
lpProxyEntry = gethostbyname(lpszProxyAddress);
}
else
{
// It was a valid IP address string
lpProxyEntry = gethostbyaddr((const char *)&iaProxy,
sizeof(struct in_addr), AF_INET);
}
if (lpProxyEntry == NULL)
{
printf("gethostbyname()");
return 0;
}
// Fill in the rest of the proxy address structure
SOCKADDR_IN saProxy;
saProxy.sin_port = htons(nProxyPort);
saProxy.sin_family = AF_INET;
saProxy.sin_addr = *((LPIN_ADDR)*lpProxyEntry->h_addr_list);
// Create a TCP/IP stream socket
SOCKET sock;
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET)
{
printf("socket()");
return 0;
}
//connect to proxy
if(connect(sock, (LPSOCKADDR)&saProxy, sizeof(SOCKADDR_IN)))
{
return 0;
}
char szBuffer[4096];
int nLen;
if(stricmp(lpszProxyProtocol, "HTTPS") == 0 || stricmp(lpszProxyProtocol, "HTTP") == 0 )
{
if(bNeedAuth)
{
//Proxy-Authorization: Basic
char szAuth[1024 + 1] = {""};
char szAuthT[1024 + 1] = {""};
sprintf(szAuthT, "%s:%s", lpszUserName,lpszPassword);
to64frombits((UCHAR *)szAuth, (UCHAR *)szAuthT, strlen(szAuthT));
sprintf(szBuffer, "CONNECT %s:%d HTTP/1.0\r\nProxy-Authorization: Basic %s\r\n\r\n", lpszDestHost, nDestPort, szAuth);
}
else
{
sprintf(szBuffer, "CONNECT %s:%d HTTP/1.0\r\n\r\n", lpszDestHost, nDestPort);
}

nLen = strlen(szBuffer);
send(sock, szBuffer, nLen, 0);
nLen = 4096;
recv(sock, szBuffer, nLen, 0);
printf("%s\n",szBuffer);
if(strnicmp(szBuffer, "HTTP/1.0 200", strlen("HTTP/1.0 200")) == 0 ||
strnicmp(szBuffer, "HTTP/1.1 200", strlen("HTTP/1.1 200")) == 0)
{
return 1;
}
return 0;
}
...全文
278 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdljf 2004-07-28
  • 打赏
  • 举报
回复
搞定了,ms的proxy认证这么麻烦。
老外的代码也太值钱了,就实现这么一个proxy认证,竟然一个lib开价$800以上,晕死了,我自己也写了一个lib实现这个功能,用了两天时间。

我要结贴了,心情高兴,来者有分
xdljf 2004-07-28
  • 打赏
  • 举报
回复
NTLM的认证要经过这么几步,供大家参考:
1: C --> S GET ...

2: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM

3: C --> S GET ...
Authorization: NTLM <base64-encoded type-1-message>

4: C <-- S 401 Unauthorized
WWW-Authenticate: NTLM <base64-encoded type-2-message>

5: C --> S GET ...
Authorization: NTLM <base64-encoded type-3-message>

6: C <-- S 200 Ok
ydfok 2004-07-28
  • 打赏
  • 举报
回复
那你两天公司要给你多少工资?
起码也要400吧~~

所以说,价钱其实还是差不多的.
顺便说说你改了些什么?
ydfok 2004-07-28
  • 打赏
  • 举报
回复
你强~~~
xdljf 2004-07-27
  • 打赏
  • 举报
回复
up 有分,郁闷
xdljf 2004-07-26
  • 打赏
  • 举报
回复
我当然有用户名、密码呀,使用internet函数族可以通过,用socket写了一个小程序就过不去了,郁闷
会思考的草 2004-07-26
  • 打赏
  • 举报
回复
MS的ISA防火墙,需要用户名密码验证的吧?

18,356

社区成员

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

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