Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert how to get the stat code from ...

Replytotopic

how to get the stat code from the header of repsonse

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

My code is as follows client = HTTPClient.new response= client.get(‘http://localhost:3000/’)
My response header is as follows
client.get(‘http://localhost:3000/’)= #<http::message:0x537e290> @peer_cert = nil @header = #<http::message::headers:0x537e27c> @request_via_proxy = nil @response_status_code = 200 @body_charset = nil @request_query = nil @http_version = 1.1 @header_item = Array (6 element(s)) @request_method = nil @body_type = nil @request_uri = nil @chunked = false @body_date = nil @is_request = false @reason_phrase = OK @body_size = 0 StatusCodeMap = Hash (12 element(s)) CharsetMap = Hash (4 element(s)) @body = #<http::message::body:0x537e268> @@mime_type_func = nil Headers = HTTP::Message::Headers @inheritable_attributes = Empty Hash @@attr_internal_naming_format = @_%s CRLF = Body = HTTP::Message::Body

My requirement is to read the @response_status_code from the above header .Please give me some idea about this.
Thanks in advance.

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Hi,

client = HTTPClient.new

=> [...]

response = client.get “http://google.com”

=> [...]

response.status

=> 301

response.reason

=> “Moved Permanently”

Jon

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

i gan get it by” response.response_status_code”
it will return the particular as e.g. 200 or 400 or 302 like this.

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Don’t know which HTTPClient you’re using, but the version I have doesn’t have a response_status_code method. It’s definitely just response.status.

response.status
=> 301
response.response_status_code
NoMethodError: undefined method `response_status_code' for #<http::message:0x1250188>
  from (irb):8
response.status_code
NoMethodError: undefined method `status_code' for #<http::message:0x1250188>
  from (irb):9
 
Profile

Authority 12
Posting Rating 95
Sign in to rate this post

I am not able to install the httpclient gem, is there any other source from where i can get it?

gem install httpclient
ERROR: While executing gem … (Gem::InstallError) invalid gem format for c:/ruby/lib/ruby/gems/1.8/cache/httpclient-2.1.2.gem

 
Profile

Authority 0
Posting Rating 16
Sign in to rate this post

hi , just down load httpclient and put it in application folder.and then install it from command prompt.make sure your ruby gem version and ruby is 1.8.5 more than that.or else check which httpclient is suitable for your application.from the ruby forge site.
http://gems.rubyforge.vm.bytemark.co.uk/gems/

Replytotopic

Other Recent Topics

Ask a Rails expert : Sanitizing html

Ask a Rails expert : First post, requesting sage perspective

Ask a Rails expert : How to use mephisto

Ask a Rails expert : How to use mephisto

Ask a Rails expert : will_paginate customization problem

Ask a Rails expert : BackgroundRB still wants 'development' environment...?

Ask a Rails expert : activescaffold, sql exception

Ask a Rails expert : Passing non-english chars in query string

Ask a Rails expert : Rails and 2D barcodes

Ask a Rails expert : apache giving proxy error

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel