如何在PHP中创建代理

时间:2016-10-20 01:47:52

标签: php curl proxy

我试图在PHP中创建代理。当我访问页面http://example.com时一切正常,但是使用cURL,我总是得到401 Unauthorized Error。

我的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, getallheaders());
curl_setopt($ch, CURLOPT_URL, 'http://example.com');
print_r(curl_exec($ch));

回应:

HTTP/1.1 401 Unauthorized
Content-Type: text/html
Server: Microsoft-IIS/7.5
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
X-Powered-By: ASP.NET
Date: Thu, 20 Oct 2016 01:30:11 GMT
Content-Length: 1293

0 个答案:

没有答案