无法通过php curl验证TMG

时间:2012-05-20 07:04:49

标签: php curl proxy authorization

我想通过curl在网络中使用代理打开网页。但遗憾的是TMG服务器无法验证我并返回407错误。 这是我的代码:

$ch = curl_init("http://google.com");;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "http://192.168.4.10:8080");
curl_setopt($ch, CURLOPT_PROXYPORT,8080);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "8909103:uvixqr");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
//curl_setopt($ch, CURLOPT_HEADER, 1);
$x = curl_exec($ch);
var_dump($x);
curl_close($ch);

并返回以下错误:

Network Access Message: The page cannot be displayed
Explanation: There is a problem with the page you are trying to reach and it cannot be displayed. 

Try the following:
Refresh page: Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
Check spelling: Check that you typed the Web page address correctly. The address may have been mistyped.
Access from a link: If there is a link to the page you are looking for, try accessing the page from that link.
If you are still not able to view the requested page, try contacting your administrator or Helpdesk. 

Technical Information (for support personnel)
Error Code: 407 Proxy Authentication Required. Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. (12209)
IP Address: 192.168.4.10
Date: 5/20/2012 6:51:36 AM [GMT]
Server: ISA3.ee.kntu.local
Source: proxy

问题在哪里,我该如何解决?

2 个答案:

答案 0 :(得分:3)

curl TMG(ISA3)身份验证:

url_setopt($ ch,CURLOPT_PROXYAUTH,CURLAUTH_NTLM);

curl_setopt($ch, CURLOPT_PROXY, "http://proxyserver:8080");
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "yourdomain.com\username:password");

它有效;)

答案 1 :(得分:0)

您正在设置代理端口两次:

curl_setopt($ch, CURLOPT_PROXY, "http://192.168.4.10:8080");
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);

在CURLOPT_PROXY设置中删除:8080,并将CURLOPT_PROXYPORT值放在引号中:

curl_setopt($ch, CURLOPT_PROXY, "http://192.168.4.10");
curl_setopt($ch, CURLOPT_PROXYPORT,"8080");

将其设置为详细模式也很有帮助:

curl_setopt($ch, CURLOPT_VERBOSE, 1);