如何使用PHP中的cURL连接到Tor隐藏服务
|
我正在尝试使用以下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); 当我运行它时,我收到以下错误: Couldn't resolve host name 但是,当我从Ubuntu中的命令行运行以下命令时: curl -v --socks5-hostname localhost:9050 http://jhiwjjlqpyawmpjx.onion 我得到了预期的回应 PHP cURL文档说明了这一点: --socks5-hostname Use the specified SOCKS5 proxy (and let the proxy resolve the host name). 我相信它从命令行工作的原因是因为Tor(代理)正在解析它识别的.onion主机名。在运行上面的PHP代码时,我的猜测是cURL或PHP正在尝试解析.onion主机名并且无法识别它。我已经搜索了一种告诉cURL / PHP让代理解析主机名的方法,但我找不到办法。 看起来CURLPROXY_SOCKS5_HOSTNAME没有在PHP中定义,但您可以显式使用其值,它等于7: curl_setopt($ch,7); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
