Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3807542
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:00:28+00:00 2026-05-19T15:00:28+00:00

I am experimenting with Net::HTTP in Rails 3.0.3 but can’t get it to work

  • 0

I am experimenting with Net::HTTP in Rails 3.0.3 but can’t get it to work due to a Timeout::Error.

I am having two controllers: Controller A is called by Controller B.

Controller A (xml_provider_controller.rb):

class XmlProviderController < ApplicationController
  def availabilityByDateRequest
    respond_to do |format|
      format.xml # availabilityByDateRequest.xml.builder
    end
  end
end

File “availabilityByDateRequest.xml.builder” is a simple static XML which works.

Controller B (mains_controller.rb):

require 'nokogiri'
require 'net/http'
require 'uri'
require "logger"

class MainsController < ApplicationController

  def search

    url = URI.parse("http://127.0.0.1:3000/xmlprovider/availabilityByDateRequest/")
    http = Net::HTTP.new(url.host, url.port)
    http.open_timeout = 10 # in seconds
    http.read_timeout = 10 # in seconds
    req = Net::HTTP::Post.new(url.path, 
                              initheader = {'Content-Type' => 'application/xml', 
                                            'Accept' => 'application/xml'})
    req.body = "<?xml version='1.0' encoding='UTF-8'?><somedata></somedata>"
    res = http.request(req)

    logger.debug res.body

    xml_doc = Nokogiri::XML(res.body)
    @results = xml_doc.xpath('//startLocation')

    respond_to do |format|
      format.html # search.html.erb
    end

  end
end

Ok, “req.body” is not required at this point because only a static XML is returned by Controller B. However, a dynamically generated XML will be sent to Controller A and processed accordingly in the future, so I left it in.

I also defined a route:

match 'xmlprovider/availabilityByDateRequest' => 'xml_provider#availabilityByDateRequest', :via => :post, :format => 'xml'

Once I call “http://0.0.0.0:3000/mains/search“, I get a Timeout::Error.

The log says:

Started GET "/mains/search" for 127.0.0.1 at 2011-01-30 10:48:17 +0100
opening connection to localhost...
opened
<- "POST /xmlprovider/availabilityByDateRequest/ HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: localhost:3000\r\nContent-Length: 136\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n"
<- "<?xml version='1.0' encoding='UTF-8'?><somedata></somedata>"
Conn close because of error Timeout::Error
Timeout::Error (Timeout::Error):
  app/controllers/mains_controller.rb:43:in `search'
Processing by MainsController#search as HTML
...
Started POST "/xmlprovider/availabilityByDateRequest/" for 127.0.0.1 at 2011-01-30 10:48:27 +0100
  Processing by XmlProviderController#availabilityByDateRequest as XML
  Parameters: {"<?xml version"=>"'1.0' encoding='UTF-8'?><somedata><name>Test Name 1</name><description>Some data for Unit testing</description></somedata>"}
Rendered xml_provider/availabilityByDateRequest.xml.builder (8.8ms)
Completed 200 OK in 14ms (Views: 13.9ms | ActiveRecord: 0.0ms)

According to the log, Controller B is called and returns the XML (last line in the log).

However, what causes the Timeout::Error? It’s certainly not a “timeout” in terms of insufficient processing time. Something gets stuck somewhere, most probably at line “res = http.request(req)“

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:00:29+00:00Added an answer on May 19, 2026 at 3:00 pm

    Are you POSTing into your ‘current application’? If you are, you probably need to make sure you have at least two back end processes handling requests, otherwise this one method will lock itself. If you have two back end processes handling requests, then you better hope they aren’t both making this same request 😉 and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been experimenting with sending messages from two .NET Windows Forms applications using
I'm experimenting with asp.net routing (using webforms). I got it to work fine and
I've been having a crack at some of the problems over at http://projecteuler.net/ with
I'm keen to get started experimenting with gzip, but like i used to find
Please check the following JSFiddle: http://jsfiddle.net/rhulshof/6bd4g/4/ I'm experiencing 2 problems which I just can't
I'm experimenting with the new jdk8 what is available here http://jdk8.java.net/lambda/ I'm able to
Here's the jfiddle for what I'm trying to achieve: http://jsfiddle.net/fmvmA/ I have two issues
I'm experimenting with a design. It seems I can't get my CSS right. I
I'm experimenting with MSMQ and can get a sender/receiver working on a local machine.
I have recently been experimenting with the profile features of ASP.NET. I am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.