Hello, I''m having trouble using mechanise to post a form. I took a wireshark capture of the form being submitted by firefox and by mechanise. In both there is an HTTP Post and then a ''continuation of non-http traffic'' packet. The obvious difference is that the firefox continuation packet has some http metadata (I don''t know the proper terminology) where the mechanise packet has none. The firefox continuation packet: Content-Type: application/x-www-form-urlencoded\r\n Content-Length: 46 \r\n Wireshark then interprets what follows as ''Line-based text data: application/x-www-form-urlencoded", and this is the post data (field1=x&field2=y) The mechanize continuation packet does not contain this extra metadata, it merely contains the post data (field1=x&field2=y). Is this a problem? I''m not familiar enough with http to know. If it''s NOT a problem, any ideas where the post could be going wrong? The page I get back is just as though I had requested it without posting any data at all. Thanks, Mike
On Sat, Oct 27, 2007 at 12:54:04AM +0100, M Macnair wrote:> Hello, > > I''m having trouble using mechanise to post a form. I took a wireshark > capture of the form being submitted by firefox and by mechanise. In > both there is an HTTP Post and then a ''continuation of non-http > traffic'' packet. The obvious difference is that the firefox > continuation packet has some http metadata (I don''t know the proper > terminology) where the mechanise packet has none. > > The firefox continuation packet: > Content-Type: application/x-www-form-urlencoded\r\n > Content-Length: 46 > \r\n > Wireshark then interprets what follows as ''Line-based text data: > application/x-www-form-urlencoded", and this is the post data > (field1=x&field2=y)I''m not sure what a continuation packet is... Can you try examining the request/response with firebug or with livehttpheaders?> > The mechanize continuation packet does not contain this extra > metadata, it merely contains the post data (field1=x&field2=y). > > Is this a problem? I''m not familiar enough with http to know. If > it''s NOT a problem, any ideas where the post could be going wrong? > The page I get back is just as though I had requested it without > posting any data at all.I don''t think it should be a problem. Typically what I do to debug is to add a logger to mechanize, then compare mechanize output with livehttpheaders output and see where mechanize and firefox differ. Then get them to be the same. If you can provide a sample script that doesn''t work, I can probably help more. -- Aaron Patterson http://tenderlovemaking.com/
On 10/29/07, Aaron Patterson <aaron at tenderlovemaking.com> wrote:> On Sat, Oct 27, 2007 at 12:54:04AM +0100, M Macnair wrote: > > Hello, > > > > I''m having trouble using mechanise to post a form. I took a wireshark > > capture of the form being submitted by firefox and by mechanise. In > > both there is an HTTP Post and then a ''continuation of non-http > > traffic'' packet. The obvious difference is that the firefox > > continuation packet has some http metadata (I don''t know the proper > > terminology) where the mechanise packet has none. > > > > The firefox continuation packet: > > Content-Type: application/x-www-form-urlencoded\r\n > > Content-Length: 46 > > \r\n > > Wireshark then interprets what follows as ''Line-based text data: > > application/x-www-form-urlencoded", and this is the post data > > (field1=x&field2=y) > > I''m not sure what a continuation packet is... Can you try examining the > request/response with firebug or with livehttpheaders? >A continuation packet is where it the same http message, but stretched across multiple tcp packets. It turns out this wasn''t the problem though, both ways of sending it are perfectly valid.> > > > The mechanize continuation packet does not contain this extra > > metadata, it merely contains the post data (field1=x&field2=y). > > > > Is this a problem? I''m not familiar enough with http to know. If > > it''s NOT a problem, any ideas where the post could be going wrong? > > The page I get back is just as though I had requested it without > > posting any data at all. > > I don''t think it should be a problem. Typically what I do to debug is > to add a logger to mechanize, then compare mechanize output with > livehttpheaders output and see where mechanize and firefox differ. Then > get them to be the same.Useful advice, thanks.> > If you can provide a sample script that doesn''t work, I can probably > help more.I got it working thanks, it was a cookie issue. I don''t know whether anyone else would find it useful, but here is how I set an initial session cookie, which I didn''t find particularly obvious from the documentation: class MyMech < WWW::Mechanize def initialize(session_id) super() Cookie::parse(ROOT_URI,''_session_id='' + session_id + ''; path=/'') { |c| cookie_jar.add(ROOT_URI,c)} end end