POST followed by GET

2003-10-13 Thread Tony Lewis
I'm trying to figure out how to do a POST followed by a GET.

If I do something like:

wget http://www.somesite.com/post.cgi --post-data 'a=1&b=2' 
http://www.somesite.com/getme.html -d

I get the following behavior:

POST /post.cgi HTTP/1.0

[POST data: a=1&b=2]

POST /getme.html HTTP/1.0

[POST data: a=1&b=2]

Is this what is expected? Is there a way I can coax wget to POST to post.cgi and GET 
getme.html?

Tony

Re: POST followed by GET

2003-10-14 Thread Hrvoje Niksic
"Tony Lewis" <[EMAIL PROTECTED]> writes:

> I'm trying to figure out how to do a POST followed by a GET.
>
> If I do something like:
>
> wget http://www.somesite.com/post.cgi --post-data 'a=1&b=2' 
> http://www.somesite.com/getme.html -d

Well... `--post-data' currently affects all the URLs in the Wget run.
I'm not sure if that makes sense... perhaps it should only apply to
the first one.  But I'm not sure that makes sense either -- what if I
*want* to POST the same data to two URLs, much like you want to POST
to one and GET to the other?

Maybe the right thing would be for `--post-data' to only apply to the
URL it precedes, as in:

wget --post-data=foo URL1 --post-data=bar URL2 URL3

In that case, URL1 would be POSTed with foo, URL2 with bar, and URL3
would be fetched with GET.

But I'm not at all sure that it's even possible to do this and keep
using getopt!

What do the others think?


Re: POST followed by GET

2003-10-14 Thread Tony Lewis
Hrvoje Niksic wrote:

> Maybe the right thing would be for `--post-data' to only apply to the
> URL it precedes, as in:
>
> wget --post-data=foo URL1 --post-data=bar URL2 URL3
>

> But I'm not at all sure that it's even possible to do this and keep
> using getopt!

I'll start by saying that I don't know enough about getopt to comment on
whether Hrvoje's suggestion will work.

It's hard to imagine a situation where wget's current behavior makes sense
over multiple URLs. I'm sure someone can come up with an example, but it's
likely to be an unusual case. I see the ability to POST a form as being most
useful when a site requires some kind of form-based authentication to
proceed with looking at other pages within the site.

Some alternatives that occur to me follow.

Alternative #1. Only apply --post-data to the first URL on the command line.
(A simple solution that probably covers the majority of cases.)


Alternative #2. Allow POST and GET as keywords in the URL list so that:

wget POST http://www.somesite.com/post.cgi --post-data 'a=1&b=2' GET
http://www.somesite.com/getme.html

would explicitly specify which URL uses POST and which uses GET. If more
than one POST is specified, all use the same --post-data.


Alternative #3. Look for  tags and have --post-file specify the data
to be specified to various forms:

--form-action=URL1 'a=1&b=2'
--form-action=URL2 'foo=bar'


Alternative #4. Allow complex sessions to be defined using a "session" file
such as:

wget --session=somefile --user-agent='my robot'

Options specified on the command line apply to every URL. If somefile
contained:

--post-data 'data=foo' POST URL1
--post-data 'data=bar' POST URL2
--referer=URL3 GET URL4

It would be the same logically equivalent to the following three commands:

wget --user-agent='my robot' --post-data 'data=foo' POST URL1
wget --user-agent='my robot' --post-data 'data=bar' POST URL2
wget --user-agent='my robot' --referer=URL3 GET URL4

with wget's state maintained across the session.

Tony



Re: POST followed by GET

2003-10-14 Thread Daniel Stenberg
On Tue, 14 Oct 2003, Tony Lewis wrote:

> It would be the same logically equivalent to the following three commands:
>
> wget --user-agent='my robot' --post-data 'data=foo' POST URL1
> wget --user-agent='my robot' --post-data 'data=bar' POST URL2
> wget --user-agent='my robot' --referer=URL3 GET URL4

Just as a comparison, this approach is basicly what we've went with in curl
(curl has supported this kind of operations for years, including support for
multipart formposts which I guess is next up for adding to wget! ;-P).  There
are just too many options or specifics that you can set, so having them all
possible to change between several URLs specified on the command line makes
the command line parser complicated and the command lines even more complex.

The main thing this described approach requires (that I can think of) is that
wget would need to store session cookies as well in the cookie file (I believe
I read that it doesn't atm).

-- 
 -=- Daniel Stenberg -=- http://daniel.haxx.se -=-
  ech`echo xiun|tr nu oc|sed 'sx\([sx]\)\([xoi]\)xo un\2\1 is xg'`ol


Re: POST followed by GET

2003-10-14 Thread Hrvoje Niksic
I like these suggestions.  How about the following: for 1.9, document
that `--post-data' expects one URL and that its behavior for multiple
specified URLs might change in a future version.

Then, for 1.10 we can implement one of the alternative behaviors.



Re: POST followed by GET

2003-10-14 Thread Tony Lewis
Hrvoje Niksic wrote:

> I like these suggestions.  How about the following: for 1.9, document
> that `--post-data' expects one URL and that its behavior for multiple
> specified URLs might change in a future version.
>
> Then, for 1.10 we can implement one of the alternative behaviors.

That works for me... I can hardly wait for 1.9 to get wrapped up so we can
start working on 1.10.

Hrvoje, has anyone mentioned how glad we are that you've come back?

Tony