Connect reset by peer error

Hi all

I'm getting a 'Connection reset by peer' while getting an access token during oAuth from a third party API. Here's the code snippet:

def accesstoken
  @code = params[:code]

   url = URI.parse('access token request url')
   req =
   req.set_form_data({'auth_code' => @code, 'client_id'=>'my_client_id', 'client_secret'=>'my_secret_key'}, ';')
   res =, url.port).start { |http| http.request(req) }
   case res
   when Net::HTTPSuccess, Net::HTTPRedirection
      # OK
     # res.error!

    render :text => @code.inspect


I get a valid authorization code but unable to proceed to get access token due to above error. The third party API has to return a response in json format.
Any help is much awaited and appreciated!

Is there some particular reason you’re using the semicolon separator here? Unless you’ve got a very weird server on the other end, the default separator for set_form_data (&) is almost certainly the correct thing to use.

Also note that, given that you’re sending client_secret, you should be using SSL for this connection as well - see my reply to your earlier post.

–Matt Jones