cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: problem with POST on Redirecting! ( segmentation fault )

From: Ralph Mitchell <rmitchell_at_eds.com>
Date: Tue, 03 Dec 2002 04:58:46 -0600

Firstly, did you get a core cump from the seg fault? It would help to nail down what's causing the seg fault.

To answer your questions:

    1) Don't know... It may depend on your server what it will accept. If it really doesn't want to handle GET, you may have to script the redirects yourself.

    2) Yes it can be automated. I've had instances where I couldn't let curl follow redirects. What you do is save the headers and extract the Location: from them. Keep looping until you don't get a Location:. Deal with
each new url individually. In my case, I had to switch proxy usage on and off for successive pages...

    3) use the -b and -c options to track cookies independantly of the headers.

            i.e. curl -D TESTING -c cookies -d ......
            and curl -D TESTING -b cookies -c cookies -d .....

    4) If your login page is a fill-in form, you have to fill it in and post it back. The -u option is for dealing with a popup authentication box. The thing is, no two fill-in forms have identical input variable names, so
it's almost impossible for curl to work out how to reply. In your example, you're posting back test1user & test1pass. I've got scripts that post back userid/userpass, username/passwd, username/password, etc, which might seem
easy enough to catch until you realize that the login form designer might just as easily use "cricket" to hold the userid and "elephant" to hold the password. Pick any two random words from the dictionary... In fact, pick any
dictionary - English, Spanish, French, etc - you see the problem?

Ralph Mitchell

Sanjeev wrote:

> Hi,
>
> I'm new to curl. As per my project specs, i need to
> write a 'c' program which fetches data from a database
> and then posts it on to web. Before i continue with
> programming, i thought to check how it works from a
> command line. Due to Redirection, though I could'nt
> use curl for my project unless if you could help me
> out!
>
> proj Details::
>
> 1) I need to post data to a page
> http://www.xxx.com/yyy/create.php
>
> 2) When I call this the first action is it will
> redirected to a login page!
>
> 3) Once on successfull login, a session is created
> and using the session, i need to POST my data.
>
> ( the home page is a frames based page, with login
> frame as second frame, which unfortunately is one
> more redirection. But If i call directly as
> specified
> in (1.) I was redirected to the login page
> automatically )
>
> Commands::
> *****************************************************
> The following worked successfully on a non=redirection
> site:
>
> curl -D SESS -d "test1user=myname" -d
> "test1pass=mypass" -d "button=Log%20in"
> http://www.xxx.com/create.php
>
> and then Posted data successfully with
> curl -b SESS -d
> "name=value&name=value&name=value&submit=Submit"
> http://www.xxx.com/create.php
> THIS IS DONE SUCCESSFULLY
> -----------------------------------------------------
> THe Failed program:
> ( since it is failing due to redirection, i needed to
> use the '-L' option )
> -------------------
> COMMAND::
> curl -v -D TESTING -d "test1user=sanjeev" -d
> "test1pass=sanjeev" -d "button=Login" -L
> http://web.xxx.com/yyy/create.php
> -------------------
> OUTPUT::
>
> * About to connect() to web.xxx.com:80
> * Connected to web.xxx.com (192.168.0.59) port 80
> > POST /yyy/create.php HTTP/1.1
> User-Agent: curl/7.10.2 (i686-pc-linux-gnu)
> libcurl/7.10.2 OpenSSL/0.9.6c zlib/1.1.3
> Host: web.xxx.com
> Pragma: no-cache
> Accept: image/gif, image/x-xbitmap, image/jpeg,
> image/pjpeg, */*
> Content-Length: 48
> Content-Type: application/x-www-form-urlencoded
>
> test1user=sanjeev&test1pass=sanjeev&button=Login*
> Follow to new URL:
> http://web.xxx.com/horde/login.php?Horde=a36591da71ffbddbd672330772cc9e03&url=%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03
> * Connection #0 left intact
> * Follows Location: to new URL:
> 'http://web.xxx.com/horde/login.php?Horde=a36591da71ffbddbd672330772cc9e03&url=%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03'
> * Disables POST, goes with GET
> * Re-using existing connection! (#0)
> Segmentation fault
>
> ----------------
> See the segmentation fault!
>
> I also tried with copying the redirected location
> manually onto the command line which read::
>
> ----------------
> COMMAND::
> curl -v -D TESTING -d "test1user=sanjeev" -d
> "test1pass=sanjeev" -d "button=Login" -L
> 'http://web.xxx.com/horde/login.php?Horde=a36591da71ffbddbd672330772cc9e03&url=%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03'
> _________________
> OUTPUT::
> * About to connect() to web.xxx.com:80
> * Connected to web.xxx.com (192.168.0.59) port 80
> > POST
> /horde/login.php?Horde=a36591da71ffbddbd672330772cc9e03&url=%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03
> HTTP/1.1
> User-Agent: curl/7.10.2 (i686-pc-linux-gnu)
> libcurl/7.10.2 OpenSSL/0.9.6c zlib/1.1.3
> Host: web.xxx.com
> Pragma: no-cache
> Accept: image/gif, image/x-xbitmap, image/jpeg,
> image/pjpeg, */*
> Content-Length: 48
> Content-Type: application/x-www-form-urlencoded
>
> test1user=sanjeev&test1pass=sanjeev&button=Login*
> Follow to new URL:
> http://web.xxx.com/horde/test1/login.php?Horde=a36591da71ffbddbd672330772cc9e03&redirect_url=http%3A%2F%2Fweb.xxx.com%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03%26Horde%3Da36591da71ffbddbd672330772cc9e03
> * Connection #0 left intact
> * Follows Location: to new URL:
> 'http://web.xxx.com/horde/test1/login.php?Horde=a36591da71ffbddbd672330772cc9e03&redirect_url=http%3A%2F%2Fweb.xxx.com%2Fyyy%2Fcreate.php%3FHorde%3Da36591da71ffbddbd672330772cc9e03%26Horde%3Da36591da71ffbddbd672330772cc9e03'
> * Disables POST, goes with GET
> * Re-using existing connection! (#0)
> Segmentation fault
>
> _________________
> And again there is a Seg Fault!
>
> ( one more thing, actually i forgot to take off the -L
> from the command
> line, fortunately this showed me that there is one
> more
> redirection )
>
> Now I again copied down the redirected link on the
> command line. This time it worked though, but the page
> is not submitted. I see a page with the user name
> filled in! but it was not submitted!
>
> *****************************************************
> Few Questions::
>
> 1) According to the Documentation, on a redirection
> GET takes over POST. But my login page needed a POST!
> what should i do?
>
> 2) Lets say I could manage some how with the POST/GET
> of the login page, But as you saww above, i needed to
> copy the Followed URL twice MANUALLY to get the login
> page. Couldn't this be automated!
>
> 3) Finally, -D TESTING, dumped the session to the file
> TESTING, but on using the -L option, all the headers,
> it passed through redirection were appended to this
> same file, until the Final URL. NOW if lets say, the
> login is successfull, then the returned session is
> towards the end of the file 'TESTING' after all the
> redirected url's headers!
> Now if I use -b TESTING, will that will it read the
> session from the end of the file?? i mean the
> succesful
> header part of the TESTING??
>
> 4) also, could you please explain me why cant i submit
> the LOGIN pages with -u "myusername:mypassword" ??
> **************************************************
>
> Few Sorries/sorry's/??
>
> I'm sorry, i needed to modify the command line and
> the output to keep up my company's privacy!
>
> and second sorry for such a huge mail
>
> and third sorry for not giving the version numbers and
> environments, hoping that you will read them from the
> output, i copied.
>
> -----------------
> Hoping and wishing for a POSITIVE reply. If its not
> possible with curl (**I shouldn't say this! sorry**)
> please refer me to some package/library, i could use
> for doing this!
> -----------------
> BYe!
>
> --
> Sanjeev

-------------------------------------------------------
This SF.net email is sponsored by: Get the new Palm Tungsten T
handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0002en
Received on 2002-12-03