title: Ruby HTTP Library gets Connection Reset with Facebook App
body: <p>The following curl command works as expected:<br>
  <code>curl 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&amp;client_id=myappid&amp;client_secret=myclientsecret'</code></p>
  
  <p>I want to do the same thing in my Ruby program.  The following code gives me an error:</p>
  
  <pre><code>fb_access_token_url = URI.parse(                                             
      'https://graph.facebook.com/oauth/access_token' +                        
      '?grant_type=client_credentials' +                                       
      '&amp;client_id=' + FACEBOOK_APP_ID +                                        
      '&amp;client_secret=' + FACEBOOK_APP_SECRET)                                 
  fb_access_token = Net::HTTP.get(fb_access_token_url)                         
  </code></pre>
  
  <p>So does this code:</p>
  
  <pre><code>fb_access_token_host = 'graph.facebook.com'                                  
  fb_access_token_path_and_params = (                                          
      '/oauth/access_token' +                                                  
      '?grant_type=client_credentials' +                                       
      '&amp;client_id=' + FACEBOOK_APP_ID +                                        
      '&amp;client_secret=' + FACEBOOK_APP_SECRET)                                 
  https_port = Net::HTTP.https_default_port()                                  
  
  fb_access_token = Net::HTTP.get_response(fb_access_token_host,               
                                           fb_access_token_path_and_params,       
                                           https_port)
  </code></pre>
  
  <p>The error is as follows:</p>
  
  <pre><code>Errno::ECONNRESET: Connection reset by peer
  /usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
  /usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
  /usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
  /usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
  /usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
  /usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
  /usr/lib/ruby/1.8/net/protocol.rb:126:in `readline'
  /usr/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
  /usr/lib/ruby/1.8/net/http.rb:2017:in `read_new'
  /usr/lib/ruby/1.8/net/http.rb:1051:in `request'
  /usr/lib/ruby/1.8/net/http.rb:948:in `request_get'
  /usr/lib/ruby/1.8/net/http.rb:380:in `get_response'
  /usr/lib/ruby/1.8/net/http.rb:543:in `start'
  /usr/lib/ruby/1.8/net/http.rb:379:in `get_response'
  /usr/lib/ruby/1.8/net/http.rb:356:in `get'
  ./test-login-and-registration.rb:182:in `test_facebook_register'
  </code></pre>
  
  <p>I'm using Ruby 1.8.7 on Ubuntu 12.04</p>