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.
------_ extPart_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 RI.parse(someURL)
# Get the proxy server and port.
proxy NV['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 ttp.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 <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 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 RI.parse("http://www.example.com/index.html")
> > content et::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.
************************************************************************************
------_ extPart_001_01C26ED8.61FD3290
Content-Type: text/html; charset="windows-1251"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: reading from a URL</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>This is what I'm currently doing to read from a URL through the company proxy server and it's working.</FONT>
</P>
<P><FONT SIZE=2> uri = URI.parse(someURL)</FONT>
<BR><FONT SIZE=2> </FONT>
<BR><FONT SIZE=2> # Get the proxy server and port.</FONT>
<BR><FONT SIZE=2> proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']</FONT>
<BR><FONT SIZE=2> %r{(\w+)://([\w.]+):(\d+)}.match(proxy)</FONT>
<BR><FONT SIZE=2> protocol, server, port = $1, $2, $3</FONT>
<BR><FONT SIZE=2> </FONT>
<BR><FONT SIZE=2> # Connect through the proxy server ifhere is one.</FONT>
<BR><FONT SIZE=2> Net::<A HREF="HTTP::Proxy(server" TARGET="_blank">HTTP::Proxy(server</A>, port).start(uri.host) do |http|</FONT>
<BR><FONT SIZE=2> response = http.get(uri.request_uri)</FONT>
<BR><FONT SIZE=2> # use response.body</FONT>
<BR><FONT SIZE=2> end</FONT>
</P>
<P><FONT SIZE=2>> -----Original Message-----</FONT>
<BR><FONT SIZE=2>> From: Alexander Bokovoy [mailto:a.bokovoy / sam-solutions.net]</FONT>
<BR><FONT SIZE=2>> Sent: Tuesday, October 08, 2002 4:55 AM</FONT>
<BR><FONT SIZE=2>> To: ruby-talk / ruby-lang.org</FONT>
<BR><FONT SIZE=2>> Subject: Re: reading from a URL</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> On Tue, Oct 08, 2002 at 03:22:07AM +0900, GOTO Kentaro wrote:</FONT>
<BR><FONT SIZE=2>> > At Tue, 8 Oct 2002 02:33:52 +0900,</FONT>
<BR><FONT SIZE=2>> > Volkmann, Mark <Mark.Volkmann / AGEDWARDS.com> wrote:</FONT>
<BR><FONT SIZE=2>> > > I need to read the content of an HTTP URL. I can break </FONT>
<BR><FONT SIZE=2>> the URL up into</FONT>
<BR><FONT SIZE=2>> > > server, port and path and use Net::HTTP to read it, but </FONT>
<BR><FONT SIZE=2>> it seems like there</FONT>
<BR><FONT SIZE=2>> > > should be an easier way. I'd reallyike to pass the URL </FONT>
<BR><FONT SIZE=2>> string to a method</FONT>
<BR><FONT SIZE=2>> > > of some class that would return an objectrom a class </FONT>
<BR><FONT SIZE=2>> that inherits from</FONT>
<BR><FONT SIZE=2>> > > IO. Does something like that exist? If not, is there an </FONT>
<BR><FONT SIZE=2>> easier way than</FONT>
<BR><FONT SIZE=2>> > > using Net::HTTP?</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > If you have Ruby 1.7, try</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > require "net/http"</FONT>
<BR><FONT SIZE=2>> > require "uri"</FONT>
<BR><FONT SIZE=2>> > content = </FONT>
<BR><FONT SIZE=2>> Net::HTTP.get_print(URI.parse("<A HREF="http://www.example.com/index.html" TARGET="_blank">http://www.example.com/index.html</A>"))</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > If not, </FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > require "net/http"</FONT>
<BR><FONT SIZE=2>> > require "uri"</FONT>
<BR><FONT SIZE=2>> > uri = URI.parse("<A HREF="http://www.example.com/index.html" TARGET="_blank">http://www.example.com/index.html</A>")</FONT>
<BR><FONT SIZE=2>> > content = Net::HTTP.get(uri.host, uri.request_uri, uri.port)</FONT>
<BR><FONT SIZE=2>> > </FONT>
<BR><FONT SIZE=2>> > Read net/http.rb if you would need http auth, redirection </FONT>
<BR><FONT SIZE=2>> or proxy server. </FONT>
<BR><FONT SIZE=2>> > This library includes the documentation of itself. </FONT>
<BR><FONT SIZE=2>> BTW, current Net::HTTP code does not support proxies with </FONT>
<BR><FONT SIZE=2>> authentication</FONT>
<BR><FONT SIZE=2>> enabled which makes it rather unusable in corporateetworks. </FONT>
<BR><FONT SIZE=2>> I've sent a</FONT>
<BR><FONT SIZE=2>> patch to fix it to Matz and he forwarded it to Minero Anoki </FONT>
<BR><FONT SIZE=2>> (net/http.rb</FONT>
<BR><FONT SIZE=2>> maintainer) but fix still isn't in CVS.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> I'm attaching it here in meantime.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> -- </FONT>
<BR><FONT SIZE=2>> / Alexander Bokovoy</FONT>
<BR><FONT SIZE=2>> ---</FONT>
<BR><FONT SIZE=2>> Q: What is the sound of one cat napping?</FONT>
<BR><FONT SIZE=2>> A: Mu.</FONT>
<BR><FONT SIZE=2>> </FONT>
</P>
<CODE><FONT SIZE=3><BR>
<BR>
***********************************************************************************<BR>
WARNING: All e-mail sent to and from this address will be received or<BR>
otherwise recorded by the A.G. Edwards corporate e-mail system and is<BR>
subject to archival, monitoring or review by, and/or disclosure to,<BR>
someone other than the recipient.<BR>
************************************************************************************<BR>
</FONT></CODE></BODY>
</HTML>
------_ extPart_001_01C26ED8.61FD3290--