From: "Volkmann, Mark" Date: 2002-10-08T23:39:43+09:00 Subject: Re: reading from a URL This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C26ED8.61FD3290 Content-Type: text/plain; charset="windows-1251" This is what I'm currently doing to read from a URL through the company proxy server and it's working. uri = URI.parse(someURL) # Get the proxy server and port. proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] %r{(\w+)://([\w.]+):(\d+)}.match(proxy) protocol, server, port = $1, $2, $3 # Connect through the proxy server if there is one. Net::HTTP::Proxy(server, port).start(uri.host) do |http| response = http.get(uri.request_uri) # use response.body end > -----Original Message----- > From: Alexander Bokovoy [mailto:a.bokovoy@sam-solutions.net] > Sent: Tuesday, October 08, 2002 4:55 AM > To: ruby-talk@ruby-lang.org > Subject: Re: reading from a URL > > > On Tue, Oct 08, 2002 at 03:22:07AM +0900, GOTO Kentaro wrote: > > At Tue, 8 Oct 2002 02:33:52 +0900, > > Volkmann, Mark wrote: > > > I need to read the content of an HTTP URL. I can break > the URL up into > > > server, port and path and use Net::HTTP to read it, but > it seems like there > > > should be an easier way. I'd really like to pass the URL > string to a method > > > of some class that would return an object from a class > that inherits from > > > IO. Does something like that exist? If not, is there an > easier way than > > > using Net::HTTP? > > > > If you have Ruby 1.7, try > > > > require "net/http" > > require "uri" > > content = > Net::HTTP.get_print(URI.parse("http://www.example.com/index.html")) > > > > If not, > > > > require "net/http" > > require "uri" > > uri = URI.parse("http://www.example.com/index.html") > > content = Net::HTTP.get(uri.host, uri.request_uri, uri.port) > > > > Read net/http.rb if you would need http auth, redirection > or proxy server. > > This library includes the documentation of itself. > BTW, current Net::HTTP code does not support proxies with > authentication > enabled which makes it rather unusable in corporate networks. > I've sent a > patch to fix it to Matz and he forwarded it to Minero Anoki > (net/http.rb > maintainer) but fix still isn't in CVS. > > I'm attaching it here in meantime. > > -- > / Alexander Bokovoy > --- > Q: What is the sound of one cat napping? > A: Mu. > *********************************************************************************** WARNING: All e-mail sent to and from this address will be received or otherwise recorded by the A.G. Edwards corporate e-mail system and is subject to archival, monitoring or review by, and/or disclosure to, someone other than the recipient. ************************************************************************************ ------_=_NextPart_001_01C26ED8.61FD3290 Content-Type: text/html; charset="windows-1251" Content-Transfer-Encoding: quoted-printable RE: reading from a URL

This is what I'm currently doing to read from a URL throu= gh the company proxy server and it's working.

    uri =3D URI.parse(someURL)
   
    # Get the proxy server and port.
    proxy =3D ENV['HTTP_PROXY'] || ENV['h= ttp_proxy']
    %r{(\w+)://([\w.]+):(\d+)}.match(prox= y)
    protocol, server, port =3D $1, $2, $3=
   
    # Connect through the proxy server if= there is one.
    Net::HTTP::Proxy(server, port).start(uri.host) do |http|
      response =3D http.get(uri= .request_uri)
      # use response.body
    end

> -----Original Message-----
> From: Alexander Bokovoy [mailto:a.bokovoy@sam-solutions.net]
> Sent: Tuesday, October 08, 2002 4:55 AM
> To: ruby-talk@ruby-lang.org
> Subject: Re: reading from a URL
>
>
> On Tue, Oct 08, 2002 at 03:22:07AM +0900, GOTO Kent= aro wrote:
> > At Tue, 8 Oct 2002 02:33:52 +0900,
> > Volkmann, Mark <Mark.Volkmann@AGEDWARDS.com= > wrote:
> > > I need to read the content of an HTTP URL= .  I can break
> the URL up into
> > > server, port and path and use Net::HTTP t= o read it, but
> it seems like there
> > > should be an easier way.  I'd really= like to pass the URL
> string to a method
> > > of some class that would return an object= from a class
> that inherits from
> > > IO.  Does something like that exist?=   If not, is there an
> easier way than
> > > using Net::HTTP?
> >
> > If you have Ruby 1.7, try
> >
> >   require "net/http"
> >   require "uri"
> >   content =3D
> Net::HTTP.get_print(URI.parse("http://www.example.com/ind= ex.html"))
> >
> > If not,
> >
> >   require "net/http"
> >   require "uri"
> >   uri =3D URI.parse("http://www.example.co= m/index.html")
> >   content =3D Net::HTTP.get(uri.host= , uri.request_uri, uri.port)
> >
> > Read net/http.rb if you would need http auth, = redirection
> or proxy server.
> > This library includes the documentation of its= elf. 
> BTW, current Net::HTTP code does not support proxie= s with
> authentication
> enabled which makes it rather unusable in corporate= networks.
> I've sent a
> patch to fix it to Matz and he forwarded it to Mine= ro Anoki
> (net/http.rb
> maintainer) but fix still isn't in CVS.
>
> I'm attaching it here in meantime.
>
> --
> / Alexander Bokovoy
> ---
> Q:    What is the sound of one cat n= apping?
> A:    Mu.
>



***************************************************************************= ********
WARNING: All e-mail sent to and from this address will be received or
otherwise recorded by the A.G. Edwards corporate e-mail system and is
subject to archival, monitoring or review by, and/or disclosure to,
someone other than the recipient.
***************************************************************************= *********
------_=_NextPart_001_01C26ED8.61FD3290--