2013-08-25 16:42
浏览 92

如何从php curl访问洋葱网站? [重复]

This question already has an answer here:

I use this code:

$this->curl = curl_init();
        curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080311 Firefox/');
        curl_setopt($this->curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->curl, CURLOPT_PROXY, '');
        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);

It's returns nothing instantly. Tor is working normally, and site is accessible from tor browser. Edit: I've found that it can't resolve host ("Couldn't resolve host name" error).


图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 如何使用PHP中的cURL连接Tor隐藏服务? 4 answers


      $ this-&gt; curl = curl_init(); 
     curl_setopt($ this-&gt; curl,CURLOPT_USERAGENT,'Mozilla / 5.0(Windows;  U; Windows NT 5.1; en-US; rv: / 20080311 Firefox /'); 
     curl_setopt($ this-&gt; curl,CURLOPT_TIMEOUT,60); 
     curl_setopt($ this-  &gt; curl,CURLOPT_RETURNTRANSFER,true); 
     curl_setopt($ this-&gt; curl,CURLOPT_PROXY,''); 
     curl_setopt($ this-&gt; curl  ,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5); 
     curl_setopt($ this-&gt; curl,CURLOPT_FOLLOWLOCATION,true); 
     curl_setopt($ this-&gt; curl,CURLOPT_URL,“http://some-onion-site.onion”);  
     $ contents = curl_exec($ this-&gt; curl); 

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtkf64283 2013-08-25 16:58

    Well, I've found out that I need to set proxy type to CURLPROXY_SOCKS5_HOSTNAME:

    curl_setopt($ch, CURLOPT_PROXYTYPE, 7);

    It works fine.

    打赏 评论

相关推荐 更多相似问题