0

我正试图使用以下 PHP 代码连接 Tor 隐藏服务:

$url = 'http://jhiwjjlqpyawmpjx.onion/'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1:9050/");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
$output = curl_exec($ch);
$curl_error = curl_error($ch);
curl_close($ch);
 print_r($output);
print_r($curl_error);

当我运行它时,出现了以下错误:

<code>Couldn’t resolve host name</code>

但是,当我在 Ubuntu 的命令行中运行以下命令时:

curl -v --socks5-hostname localhost:9050 http://jhiwjjlqpyawmpjx.onion

我得到了回复。

PHP cURL 文档是这样说的

<code>--socks5-hostname
Use  the  specified  SOCKS5 <span class="hljs-title function_ invoke__">proxy</span> (<span class="hljs-keyword">and</span> let the proxy resolve the host name).</code>

我认为,命令行之所以能正常运行,是因为 Tor(代理)正在解析它所识别的 .onion 主机名。在运行上述 PHP 代码时,我猜 cURL 或 PHP 正在尝试解析 .onion 主机名,但没有识别出来。我一直在寻找告诉 cURL/PHP 让代理解析主机名的方法,但没有找到。

user65dc4e6b21aed 选择最佳答案 2024年2月26日