title: How to Build and Send an HTTP Request to a Tor Hidden Service with Ruby
body: <p>I've spent the last couple of days looking for a solution to this problem, and though there are quite a few semi-relevant questions, none of the answers show a successful use case for sending a successful HTTP request over Tor to a hidden service using Ruby.</p>
  
  <p>One thing that seems unclear in all the answers is how the Tor browser bundle acts as a proxy for requests.</p>
  
  <p>I've tried multiple avenues of attack, the most recent being an attempt to adapt <a href="https://stackoverflow.com/questions/15445285/how-can-i-connect-to-a-tor-hidden-service-using-curl-in-php">the PHP code here</a> for sending curl requests to hidden services using Ruby CURL libraries.</p>
  
  <p>This is my code using the Curb gem, which implements some of the libcurl bindings for Ruby:</p>
  
  <pre><code>require 'curb'
  
  url = 'http://am4wuhz3zifexz5u.onion' #a known, functioning hidden service
  
  c = Curl::Easy.new(url) do |curl| 
    curl.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0" #the user agent string from the most recent version of the tor browser
    curl.verbose = true
  end
  
  c.perform
  c.inspect
  </code></pre>
  
  <p>I then tried to run this through socksify, using the IP address and port specified by the Tor browser bundle's proxy settings:</p>
  
  <pre><code>$ socksify_ruby 127.0.0.1 9150 tor-test/tor-test.rb
  </code></pre>
  
  <p>This produced the following output:</p>
  
  <pre><code>* Adding handle: conn: 0x7fb1fe195e00
  * Adding handle: send: 0
  * Adding handle: recv: 0
  * Curl_addHandleToPipeline: length: 1
  * - Conn 0 (0x7fb1fe195e00) send_pipe: 1, recv_pipe: 0
  * Could not resolve host: jhiwjjlqpyawmpjx.onion
  * Closing connection 0
  </code></pre>
  
  <p>Every approach I've tried has produced a similar result: <strong>the URI for the hidden service cannot be resolved</strong></p>
  
  <p>Can anyone help me out here or point me in the right direction? I feel that since the Tor browser can connect programmatically to hidden services, we all should be able to as well : )</p>