Be aware that doing stuff like this with forms at the HTTP level can get very tricky. You generally must first establish a session with the webserver, then capture specific data regarding the session, and potentially other things like 'viewstate' and be able to include them along with the form data in your response.
Using a value from earlier won't work as that session will usually have expired, you almost always have to capture and extract the stuff you need on the fly. (you'll get really good at regular expressions, trust me) Technically, this is close to 'spoofing' and thus there are many security measures (like viewstate) that are designed to prevent spoofing that will trip you up unless you do it exactly right. This kind of stuff requires either a pretty in-depth knowledge of HTTP and how webservers maintain state and sessions, or a good tool that will do a lot of things for you. (the 'webtest' tools built into the latest version of visual studio (if you are .net folks) is actually pretty good at doing stuff like this at the protocol level, especially if your site is done in .net. ) On Aug 5, 12:40 pm, Dmitriy Korobskiy <[email protected]> wrote: > On 8/5/11 6:04 AM, Rahul Sharma wrote:> I have already tried > Net::HTTP.post_form but I guess it only works for > > forms that are on some page. > > Rahul, > > when a form is posted, the POST data in the request body contains only > pairs of HTTP-encoded form fields: NAME=VALUE > > That *might* be all you need. It does not matter much where the original > page is located keeping in mind the following two caveats: > > 1. Your target page might or might not be checking HTTP_REFERRER value > in the request's HTTP headers. HTTP_REFERRER contains the URL of the > original page, > and it should be easy to put it in when you assemble your request > "manually" in your code. > > 2. Your browser session typically contains session and maybe even > persistent cookies that keep track of (logged in) user session and get > submitted with each request. If you capture cookies, > you can put them into your request. > > I hope it helps. > > -- > DK > AIM: DKroot1, Skype: DKroot -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected]
