From michelemendel at gmail.com Wed Oct 11 04:09:57 2006 From: michelemendel at gmail.com (michele mendel) Date: Wed, 11 Oct 2006 10:09:57 +0200 Subject: [Mechanize-users] Mechanize: save and cancel doesn't work in JSPWiki Message-ID: I'm trying to submit data in JSPWiki (edit page). I can read the data in the form, but nothings get saved when I submit the page. Cancel doesn't work either. I don't get any errors. There is no JavaScript used to submit the form. After I'm logged in I do the following: def save(page, content) @agent.get(@base_url + "Edit.jsp?page=#{page}") form = @agent.page.forms.with.name('editForm') form.fields.name('_editedtext').value = content form.submit(form.buttons.first) end And this is the cancel method (the @agent already got the edit page) def cancel form = @agent.page.forms.with.name('editForm') form.submit(form.buttons.name('cancel')) end Michele NOTE: I'm guessing that the problem could be that some header data is wrong or missing, which causes JSPWiki not to handle the request. logfile INFO mech: Net::HTTP::Get: http://[A URL]:880/coswiki/Login.jsp DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:33 GMT DEBUG mech: response-header: content-type => text/html;charset=UTF-8 DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 7968 DEBUG mech: response-header: set-cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F; Path=/coswiki DEBUG mech: saved cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F INFO mech: status: 200 DEBUG mech: query: "j_username=red&j_password=red&page=Login&action=login" INFO mech: Net::HTTP::Post: http://[A URL]:880/coswiki/Login.jsp DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: content-type => application/x-www-form-urlencoded DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Login.jsp DEBUG mech: request-header: content-length => 53 DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:33 GMT DEBUG mech: response-header: content-type => text/html DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 0 DEBUG mech: response-header: set-cookie => JSPWikiAssertedName=Red; Expires=Wed, 08-Jul-2009 08:01:34 GMT DEBUG mech: response-header: location => http://[A URL]:880/coswiki/Wiki.jsp DEBUG mech: saved cookie: JSPWikiAssertedName=Red INFO mech: status: 302 INFO mech: follow redirect to: http://[A URL]:880/coswiki/Wiki.jsp INFO mech: Net::HTTP::Get: http://[A URL]:880/coswiki/Wiki.jsp DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Login.jsp DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:33 GMT DEBUG mech: response-header: content-type => text/html;charset=UTF-8 DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 15873 INFO mech: status: 200 INFO mech: Net::HTTP::Get: http://[A URL]:880/coswiki/Edit.jsp?page=OldWikiNewWikiDiff DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Wiki.jsp DEBUG mech: response-header: last-modified => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: cache-control => max-age=0 DEBUG mech: response-header: expires => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:33 GMT DEBUG mech: response-header: content-type => text/html;charset=UTF-8 DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 16598 INFO mech: status: 200 DEBUG mech: query: "page=OldWikiNewWikiDiff&action=save&edittime=1160553663011&_editedtext=Hello+Knucklehead" INFO mech: Net::HTTP::Post: http://[A URL]:880/coswiki/Edit.jsp?page=OldWikiNewWikiDiff DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: content-type => application/x-www-form-urlencoded DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Edit.jsp?page=OldWikiNewWikiDiff DEBUG mech: request-header: content-length => 88 DEBUG mech: response-header: last-modified => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: cache-control => max-age=0 DEBUG mech: response-header: expires => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: content-type => text/html;charset=UTF-8 DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 16579 INFO mech: status: 200 INFO mech: Net::HTTP::Get: http://[A URL]:880/coswiki/Logout.jsp DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Edit.jsp?page=OldWikiNewWikiDiff DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: content-type => text/html DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 0 DEBUG mech: response-header: set-cookie => JSPWikiAssertedName=; Expires=Thu, 01-Jan-1970 00:00:10 GMT DEBUG mech: response-header: location => http://[A URL]:880/coswiki/. DEBUG mech: saved cookie: JSPWikiAssertedName= INFO mech: status: 302 INFO mech: follow redirect to: http://[A URL]:880/coswiki/. INFO mech: Net::HTTP::Get: http://[A URL]:880/coswiki/. DEBUG mech: using cookie: JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: accept => */* DEBUG mech: request-header: accept-encoding => gzip,identity DEBUG mech: request-header: user-agent => Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6 DEBUG mech: request-header: cookie => JSESSIONID=C08FB593CBE5508710F02C4AFAEEA09F DEBUG mech: request-header: referer => http://[A URL]:880/coswiki/Logout.jsp DEBUG mech: response-header: date => Wed, 11 Oct 2006 08:01:34 GMT DEBUG mech: response-header: content-type => text/html;charset=UTF-8 DEBUG mech: response-header: server => Apache-Coyote/1.1 DEBUG mech: response-header: content-length => 14751 DEBUG mech: response-header: set-cookie => JSESSIONID=9DA2FF21FBD3AB05AE657E5D582FE8D5; Path=/coswiki DEBUG mech: saved cookie: JSESSIONID=9DA2FF21FBD3AB05AE657E5D582FE8D5 INFO mech: status: 200 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20061011/b86246cd/attachment.html From michelemendel at gmail.com Wed Oct 11 04:27:48 2006 From: michelemendel at gmail.com (michele mendel) Date: Wed, 11 Oct 2006 10:27:48 +0200 Subject: [Mechanize-users] Mechanize: save and cancel doesn't work in JSPWiki: Firefox header Message-ID: This the header from Firefox to the JSPWiki server when submitting the form. There is also the redirect, but I only copied the POST. POST /coswiki/Edit.jsp?page=OldWikiNewWikiDiff HTTP/1.1 Host: tns-fbu-22-091.corp.telenor.no:880 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 ,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://tns-fbu-22-091.corp.telenor.no:880/coswiki/Edit.jsp?page=OldWikiNewWikiDiff Cookie: JSPWikiSearchBox=FindPage; JSPWikiAssertedName=Red; JSESSIONID=FB660671F3E462CC7D4FB063DF3B138F Content-Type: application/x-www-form-urlencoded Content-Length: 119 page=OldWikiNewWikiDiff&action=save&edittime=1160484282247&_editedtext=The+lock+expires+in+56+minutes.zzz%0D%0A&ok=Save Michele -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20061011/a0adbe31/attachment.html From aaron_patterson at speakeasy.net Wed Oct 11 16:00:34 2006 From: aaron_patterson at speakeasy.net (Aaron Patterson) Date: Wed, 11 Oct 2006 13:00:34 -0700 Subject: [Mechanize-users] Mechanize: save and cancel doesn't work in JSPWiki In-Reply-To: References: Message-ID: <20061011200034.GA6151@eviladmins.lan> Hi Michele, On Wed, Oct 11, 2006 at 10:09:57AM +0200, michele mendel wrote: > I'm trying to submit data in JSPWiki (edit page). I can read the data > in the form, but nothings get saved when I submit the page. Cancel > doesn't work either. I don't get any errors. There is no JavaScript > used to submit the form. > This might be a dumb question, but how do you know that cancel doesn't work? What are you expecting it to do? > After I'm logged in I do the following: > > def save(page, content) > @agent.get(@base_url + "Edit.jsp?page=#{page}") > form = @agent.page.forms.with.name('editForm') > form.fields.name('_editedtext').value = content > form.submit(form.buttons.first) > end > > And this is the cancel method (the @agent already got the edit page) > > def cancel > form = @agent.page.forms.with.name('editForm') > form.submit(form.buttons.name('cancel')) > end > Michele [snip] It is hard for me to debug this from just the headers... I'd actually have to try it out. So I used the wiki set up on jspwiki.org with the following script: agent = WWW::Mechanize.new page = agent.get('http://www.jspwiki.org/Edit.jsp?page=TestPage') form = page.form('editForm') { |f| f._editedtext << "baz" } agent.submit(form, form.buttons.first) And that seems to work fine for me. Is there a place that is publicly available where you can reproduce this error? -- Aaron Patterson http://tenderlovemaking.com/ From michelemendel at gmail.com Wed Oct 11 16:35:28 2006 From: michelemendel at gmail.com (michele mendel) Date: Wed, 11 Oct 2006 22:35:28 +0200 Subject: [Mechanize-users] Mechanize: save and cancel doesn't work in JSPWiki In-Reply-To: <20061011200034.GA6151@eviladmins.lan> References: <20061011200034.GA6151@eviladmins.lan> Message-ID: On 10/11/06, Aaron Patterson wrote: > > Hi Michele, > > On Wed, Oct 11, 2006 at 10:09:57AM +0200, michele mendel wrote: > > I'm trying to submit data in JSPWiki (edit page). I can read the data > > in the form, but nothings get saved when I submit the page. Cancel > > doesn't work either. I don't get any errors. There is no JavaScript > > used to submit the form. > > > > This might be a dumb question, but how do you know that cancel doesn't > work? What are you expecting it to do? [michele] When you start to edit a page that someone else has started to edit, you'll get informed about this. My script logs in, starts to edit the page and then saves or cancels. When I want to edit the same page I get the information that 'red' is still working on it, i.e. cancel didn't work. > After I'm logged in I do the following: > > > > def save(page, content) > > @agent.get(@base_url + "Edit.jsp?page=#{page}") > > form = @agent.page.forms.with.name('editForm') > > form.fields.name('_editedtext').value = content > > form.submit(form.buttons.first) > > end > > > > And this is the cancel method (the @agent already got the edit page) > > > > def cancel > > form = @agent.page.forms.with.name('editForm') > > form.submit(form.buttons.name('cancel')) > > end > > Michele > [snip] > > It is hard for me to debug this from just the headers... I'd actually > have to try it out. So I used the wiki set up on jspwiki.org with the > following script: > > agent = WWW::Mechanize.new > page = agent.get('http://www.jspwiki.org/Edit.jsp?page=TestPage') > form = page.form('editForm') { |f| > f._editedtext << "baz" > } > > agent.submit(form, form.buttons.first) > > And that seems to work fine for me. Is there a place that is publicly > available where you can reproduce this error? [michele] I'll check that out. I will also try to use your code, because I got errors with agent.submit. That's why I use form.submit. -- > Aaron Patterson > http://tenderlovemaking.com/ > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20061011/ec973d9a/attachment.html From jrust at lexus.elabor.com Tue Oct 17 13:14:23 2006 From: jrust at lexus.elabor.com (Rust, Jon) Date: Tue, 17 Oct 2006 10:14:23 -0700 Subject: [Mechanize-users] form submit debugging Message-ID: <45350F6F.3050401@lexus.elabor.com> version 0.62 I've got a form that's giving me trouble (server reports invalid session ID). Unfortunately, the form is submitted using SSL so I can't use a sniffer to see the differences between the ruby mechanize version and the perl mechanize version that is working. Is there a way to change the form action within mechanize? Or a way to display the request headers? Thanks, Jon From aaron_patterson at speakeasy.net Tue Oct 17 13:48:03 2006 From: aaron_patterson at speakeasy.net (Aaron Patterson) Date: Tue, 17 Oct 2006 10:48:03 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <45350F6F.3050401@lexus.elabor.com> References: <45350F6F.3050401@lexus.elabor.com> Message-ID: <20061017174803.GA14745@eviladmins.lan> Hey Jon, On Tue, Oct 17, 2006 at 10:14:23AM -0700, Rust, Jon wrote: > version 0.62 > > I've got a form that's giving me trouble (server reports invalid session > ID). Unfortunately, the form is submitted using SSL so I can't use a > sniffer to see the differences between the ruby mechanize version and > the perl mechanize version that is working. Is there a way to change the > form action within mechanize? Or a way to display the request headers? If you set mechanize to log, it should log your request headers. So just do this: require 'logger' agent = WWW::Mechanize.new { |a| a.log = Logger.new('mech.log') } You can also change the action on the form. There is an action= method on the form, so you could just do this: form.action = '/some_location' I can help more if it is possible for you to send a sample script that breaks. > > Thanks, > Jon > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users -- Aaron Patterson http://tenderlovemaking.com/ From jrust at lexus.elabor.com Tue Oct 17 16:10:18 2006 From: jrust at lexus.elabor.com (Rust, Jon) Date: Tue, 17 Oct 2006 13:10:18 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <20061017174803.GA14745@eviladmins.lan> References: <45350F6F.3050401@lexus.elabor.com> <20061017174803.GA14745@eviladmins.lan> Message-ID: <453538AA.90705@lexus.elabor.com> Aaron Patterson wrote: > If you set mechanize to log, it should log your request headers. So > just do this: > require 'logger' > agent = WWW::Mechanize.new { |a| a.log = Logger.new('mech.log') } > > You can also change the action on the form. There is an action= method > on the form, so you could just do this: > form.action = '/some_location' > Awesome! Thanks Aaron. Great s/w BTW. OK, I've grabbed a couple of sessions via logging, and also via sniffing. The only difference I've been able to find so far between Firefox, Perl Mech and Ruby Mech is that the POST URL is encoded when using Ruby Mech. Specifically, the '&' is represented as '&': POST /page.aspx?cID=1234&ssID=ksdb... vs POST /page.aspx?cID=1234&ssID=lpwioe... Expected? If it matters, the content of the POST does not have '&' encoded like this, just the URL provided in the initial POST. Thanks again! Jon From jrust at lexus.elabor.com Tue Oct 17 16:41:37 2006 From: jrust at lexus.elabor.com (Rust, Jon) Date: Tue, 17 Oct 2006 13:41:37 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <453538AA.90705@lexus.elabor.com> References: <45350F6F.3050401@lexus.elabor.com> <20061017174803.GA14745@eviladmins.lan> <453538AA.90705@lexus.elabor.com> Message-ID: <45354001.5070302@lexus.elabor.com> I wrote: > > Specifically, the '&' is represented as '&': > > POST /page.aspx?cID=1234&ssID=ksdb... > > vs > > POST /page.aspx?cID=1234&ssID=lpwioe... > Success! I sub'd the '&' with '&' in the action attribute and everything worked. Jon From aaron.patterson at gmail.com Tue Oct 17 16:54:07 2006 From: aaron.patterson at gmail.com (Aaron Patterson) Date: Tue, 17 Oct 2006 13:54:07 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <453538AA.90705@lexus.elabor.com> References: <45350F6F.3050401@lexus.elabor.com> <20061017174803.GA14745@eviladmins.lan> <453538AA.90705@lexus.elabor.com> Message-ID: <6959e1680610171354t63bf2003m404a39df556bee44@mail.gmail.com> On 10/17/06, Rust, Jon wrote: > > Aaron Patterson wrote: > > If you set mechanize to log, it should log your request headers. So > > just do this: > > require 'logger' > > agent = WWW::Mechanize.new { |a| a.log = Logger.new('mech.log') } > > > > You can also change the action on the form. There is an action= method > > on the form, so you could just do this: > > form.action = '/some_location' > > > > Awesome! Thanks Aaron. Great s/w BTW. Thanks! I'm glad you like it! OK, I've grabbed a couple of sessions via logging, and also via > sniffing. The only difference I've been able to find so far between > Firefox, Perl Mech and Ruby Mech is that the POST URL is encoded when > using Ruby Mech. Specifically, the '&' is represented as '&': > > POST /page.aspx?cID=1234&ssID=ksdb... > > vs > > POST /page.aspx?cID=1234&ssID=lpwioe... > > Expected? If it matters, the content of the POST does not have '&' > encoded like this, just the URL provided in the initial POST. Interesting! This is not expected, and looks like a bug. Can you view the source of the page and send me the action of the form? I think I know what is wrong, and I'll try to reproduce it. Thanks again! > Jon > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > -- Aaron Patterson http://tenderlovemaking.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20061017/008b00a8/attachment.html From aaron.patterson at gmail.com Tue Oct 17 17:18:45 2006 From: aaron.patterson at gmail.com (Aaron Patterson) Date: Tue, 17 Oct 2006 14:18:45 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <45354001.5070302@lexus.elabor.com> References: <45350F6F.3050401@lexus.elabor.com> <20061017174803.GA14745@eviladmins.lan> <453538AA.90705@lexus.elabor.com> <45354001.5070302@lexus.elabor.com> Message-ID: <6959e1680610171418m5440e058x22cbc4f96ef14d9a@mail.gmail.com> On 10/17/06, Rust, Jon wrote: > > I wrote: > > > > Specifically, the '&' is represented as '&': > > > > POST /page.aspx?cID=1234&ssID=ksdb... > > > > vs > > > > POST /page.aspx?cID=1234&ssID=lpwioe... > > > > Success! I sub'd the '&' with '&' in the action attribute and > everything worked. Excellent. I am adding test cases code code which should fix this! Jon > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > -- Aaron Patterson http://tenderlovemaking.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20061017/60c7a28f/attachment.html From jrust at lexus.elabor.com Tue Oct 17 17:42:18 2006 From: jrust at lexus.elabor.com (Rust, Jon) Date: Tue, 17 Oct 2006 14:42:18 -0700 Subject: [Mechanize-users] form submit debugging In-Reply-To: <6959e1680610171354t63bf2003m404a39df556bee44@mail.gmail.com> References: <45350F6F.3050401@lexus.elabor.com> <20061017174803.GA14745@eviladmins.lan> <453538AA.90705@lexus.elabor.com> <6959e1680610171354t63bf2003m404a39df556bee44@mail.gmail.com> Message-ID: <45354E3A.5080401@lexus.elabor.com> Aaron Patterson wrote: > > Interesting! This is not expected, and looks like a bug. Can you > view the source of the page and send me the action of the form? I > think I know what is wrong, and I'll try to reproduce it. > > form name="Form1" method="post" action="page.aspx?cID=1234&ssID=14d..." id="Form1" I never noticed it was presented in the source with the encoding present. Jon