[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Browsing with Cookies

Jim Van Fleet

5/25/2005 1:31:00 PM

I am writing an app that takes in some basic data and then scours some
known Internet locations for more data relevant to the input.

One of them relys on cookies to get the data in a form I can use.
Net::HTTP appears not to use cookies, even if you're inside the same
start block.

Does open-uri offer cookies? I was under the impression that it was
more of a wrapper.

Is there a way to provide a cookie? I could likely synthesize the
information that the server was looking for.

Cheers,

Jim


4 Answers

John Labovitz

5/25/2005 4:11:00 PM

0

On May 25, 2005, at 6:30 AM, Jim Van Fleet wrote:

> One of them relys on cookies to get the data in a form I can use.
> Net::HTTP appears not to use cookies, even if you're inside the
> same .start block.

WWW::Mechanize provides cookies, and may be a better solution for
your application anyway. It parses HTML and handles context, unlike
the lower-level Net::HTTP.

You can get it as a gem named 'mechanize', or from: http://
www.ntecs.de/blog/Blog/WWW-Mechanize.rdoc

--
John Labovitz
Macintosh support, research, and software development
John Labovitz Consulting, LLC
johnl@johnlabovitz.com | +1 503.949.3492 | www.johnlabovitz.com/
consulting



Markus

5/25/2005 9:31:00 PM

0

On Wed, 2005-05-25 at 06:30, Jim Van Fleet wrote:
> I am writing an app that takes in some basic data and then scours some
> known Internet locations for more data relevant to the input.
>
> One of them relys on cookies to get the data in a form I can use.
> Net::HTTP appears not to use cookies, even if you're inside the same
> .start block.
>
> Does open-uri offer cookies? I was under the impression that it was
> more of a wrapper.
>
> Is there a way to provide a cookie? I could likely synthesize the
> information that the server was looking for.
>
> Cheers,
>
> Jim

I posted a solution to this as an example in the rails wiki; see

http://wiki.rubyonrails.com/rails/show/ExampleCooki...

and

http://wiki.rubyonrails.com/rails/show/HowToRenderPr...

--MarkusQ



Jim Van Fleet

5/27/2005 9:57:00 PM

0

Markus wrote:
> On Wed, 2005-05-25 at 06:30, Jim Van Fleet wrote:
>
> I posted a solution to this as an example in the rails wiki; see
>
> http://wiki.rubyonrails.com/rails/show/ExampleCooki...
>
> and
>
> http://wiki.rubyonrails.com/rails/show/HowToRenderPr...
>
> --MarkusQ
>

For those in the future who stumble upon this thread, it was a hacked to
death version of this solution that worked for me. I had to hack the
cookie jar so that it worked on only the root domain, as it was a domain
wide cookie that I needed to use.

WWW:Mechanize looks awesome, but at this time isn't really useable for
me. I have enough trouble on my plate without having to maintain my
installation of ruby-current; 1.8.2 is not new enough.

Since this solution did work, I'm sure I could study the problem and
come up with something better based on the RFC, but I think I'll stick
with what I've got.

Cheers,

Jim


NAKAMURA, Hiroshi

5/29/2005 2:22:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Jim Van Fleet wrote:
> I am writing an app that takes in some basic data and then scours some
> known Internet locations for more data relevant to the input.
>
> One of them relys on cookies to get the data in a form I can use.
> Net::HTTP appears not to use cookies, even if you're inside the same
> .start block.
>
> Does open-uri offer cookies? I was under the impression that it was
> more of a wrapper.
>
> Is there a way to provide a cookie? I could likely synthesize the
> information that the server was looking for.

I know you already found the way... But FYI and ADV.

Type "http cookie" at the right top corner box of RAA
(http://raa.ruby...) to find http-access2. Here's a sample:
http://raa.ruby...gonzui/markup/http-access2/sample/howto.rb

Regards,
// NaHi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFCmc/sf6b33ts2dPkRAseuAKCfESqMzXzJWERQvrGYavESr0NNPgCgyypY
z4q1Fr2jLIfxSbQkr66htuM=
=2hOd
-----END PGP SIGNATURE-----