What is the meaning of #<Net::HTTPFound:0x29b78f8>

Dear All:

I am trying to deal with the http response. I am using following code to
do so.

<code>

  require 'net/http'
    require 'uri'

    def fetch(uri_str, limit = 10)
      # You should choose better exception.
      raise ArgumentError, 'HTTP redirect too deep' if limit == 0

      response = Net::HTTP.get_response(URI.parse(uri_str))
      case response
      when Net::HTTPSuccess then response
      when Net::HTTPRedirection then fetch(response['location'], limit -
1)
      else
        response.error!
      end
    end

    print fetch('http://www.gosocially.com/index.php')

</code>

I am getting output: #<Net::HTTPFound:0x29b78f8>

Please tell me what is the meaning of #<Net::HTTPFound:0x29b78f8> ?

Thanks,
Amit

···

--
Posted via http://www.ruby-forum.com/.

Dear All:

I am trying to deal with the HTTP response. I want to retrieve the
contents such as header, post, response, HTML, JSON, etc. of the HTTP
response.
(Please refer screen shot for the same.)

Please tell how to retrieve these contents?

Thanks,
Amit.

Attachments:
http://www.ruby-forum.com/attachment/6244/http_responce.JPG

···

--
Posted via http://www.ruby-forum.com/.

Amit Bobade wrote in post #1001497:

Please tell me what is the meaning of #<Net::HTTPFound:0x29b78f8> ?

According to ruby's Net::HTTPResponse docs:

xxx HTTPResponse

    1xx HTTPInformation
      100 HTTPContinue
      101 HTTPSwitchProtocol

    2xx HTTPSuccess
      200 HTTPOK
      201 HTTPCreated
      202 HTTPAccepted
      203 HTTPNonAuthoritativeInformation
      204 HTTPNoContent
      205 HTTPResetContent
      206 HTTPPartialContent

    3xx HTTPRedirection
      300 HTTPMultipleChoice
      301 HTTPMovedPermanently
      302 HTTPFound

And according to wikipedia here:

···

===
The HTTP response status code 302 Found is the most common way of
performing a redirection.[citation needed]

It is an example of industry practice contradicting the standard
HTTP/1.0 specification (RFC 1945), which required the client to perform
a temporary redirect (the original describing phrase was "Moved
Temporarily"), but popular browsers implemented it as a 303 See
Other[citation needed], i.e. changing the request type to GET regardless
of what it had been originally. Therefore, HTTP/1.1 added status codes
303 and 307 to disambiguate between the two behaviours. However, the
majority of Web applications and frameworks still use the 302 status
code as if it were the 303.[citation needed]

--
Posted via http://www.ruby-forum.com/\.

Did you read any of the documentation? Net::HTTP.get_response returns a
response object, because an HTTP request returns several different kinds of
things. What you are seeing there is the string representation of an
object.

Are you expecting to print the body of the web page? If so, then you
should print response.body, not response.

···

Amit Bobade <amit.srpce@gmail.com> wrote:

I am trying to deal with the http response. I am using following code to
do so.

<code>

require 'net/http'
   require 'uri'

   def fetch(uri_str, limit = 10)
     # You should choose better exception.
     raise ArgumentError, 'HTTP redirect too deep' if limit == 0

     response = Net::HTTP.get_response(URI.parse(uri_str))
     case response
     when Net::HTTPSuccess then response
     when Net::HTTPRedirection then fetch(response['location'], limit -
1)
     else
       response.error!
     end
   end

   print fetch('http://www.gosocially.com/index.php&#39;\)

</code>

I am getting output: #<Net::HTTPFound:0x29b78f8>

Please tell me what is the meaning of #<Net::HTTPFound:0x29b78f8> ?

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.