in reply to Can't get Mechanize to download file

I think maybe Mechanize is not able to handle cookies properly.

Nope :)

How can I get this to work?

See WWW::Mechanize::FAQ

Does it work for you from the browser? You can http://WireShark.org or LiveHTTPHeaders to figure out what works from the browser ... then get mechanize to do the same ... HTTP, thats the way it goes

  • Comment on Re: Can't get Mechanize to download file

Replies are listed 'Best First'.
Re^2: Can't get Mechanize to download file
by CJ7 (Novice) on Mar 11, 2016 at 23:02 UTC

    If it handles cookies correctly as you say then why doesn't it work?

    As I said in my question, it does work in my browser.

    When I run Wireshark I can see it getting a cookie but I don't know how to emulate this in Mechanize.

      If it handles cookies correctly as you say then why doesn't it work?

      Because of all the reasons explained in the FAQ , but basically,

      because websites still discriminate based on browser identification headers

      cookies are often set through javascript or web bugs, and mech doesn't javascript or load/GET images, you have to help it do those things

      When I run Wireshark I can see it getting a cookie but I don't know how to emulate this in Mechanize.

      Have you checked to see if mechanize is already getting this cookie?

      Have you checked to see if mechanize is getting that same url?