cURL / Mailing Lists / curl-users / Single Mail

curl-users

problem with POST on Redirecting! ( segmentation fault )

From: Sanjeev <sunaditya1_at_yahoo.com>
Date: Tue, 3 Dec 2002 02:05:43 -0800 (PST)

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
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
-------------------------------------------------------
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