3

我使用这段代码:

$this->curl = curl_init();
        curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        curl_setopt($this->curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_PROXY, '127.0.0.1:9050');
        curl_setopt($this->curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($this->curl, CURLOPT_URL, "http://some-onion-site.onion");
    $contents = curl_exec($this->curl);

它立即返回任何内容。Tor 工作正常,可以从 Tor 浏览器访问网站。编辑:我发现它无法解析主机(“无法解析主机名”错误)。

4

1 回答 1

1

好吧,我发现我需要将代理类型设置为 CURLPROXY_SOCKS5_HOSTNAME:

curl_setopt($ch, CURLOPT_PROXYTYPE, 7);

它工作正常。

于 2013-08-25T16:58:27.493 回答