cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Posting cookies along with form data

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 31 Jul 2002 14:23:38 +0200 (MET DST)

On Wed, 31 Jul 2002, preetic wrote:

> I am trying to create an application in which the client(browser)send
> login info(required to log in to a website) to the server and the server
> returns the logged in page along with the cookies.I save the cookies on
> the hard disk and want to go to another page of the website and update
> some information in it.For this i want to post the cookie file along with
> the data to be updated.

You want to post the cookie file?

> The code that i have written is functioning correctly without me sending
> the cookies back..I am not able to understand how is this working?

You don't post cookies. Cookies are passed along in regular HTTP headers.
When you tell curl to store cookies in the cookiejar, you also tell curl that
you want to engage its cookie machine. So, it'll parse incoming cookies and
use the proper ones when you do subsequent requests to sites that have
matching cookies.

> I am basically posting cookies back so that the server remembers the login
> info and lets me access any page of that website.Do i need to send the
> cookies to the server?

You don't POST cookies. And yes, if the site requires cookies your request
should include the cookies.

> If so how to do so?

You must be getting the cookies and passing them back, otherwise it isn't
working or the site is ingoring the absense of the cookies in the second
request.

> import pycurl
> import urllib
> curl=pycurl.init()
> curl.setopt(pycurl.URL,'http://www.zope.org/logged_in.html')
> dataread="__ac_name=ABC&__ac_password=wvfdgghYf&submit=Login&came_from=http://www.zope.org/login.html"
> curl.setopt(pycurl.POST,1)
> curl.setopt(pycurl.POSTFIELDS,dataread)
> curl.setopt(pycurl.COOKIEJAR,'my.txt')

Setting COOKIEJAR will make curl understand incoming cookies. They will not
be saved to the specified file until you do cleanup().

> curl.perform()
> #cookiefile=open('my.txt','r')
> #cookieread=cookiefile.readlines()
> curl.setopt(pycurl.POST,1)
> #curl.setopt(pycurl.HTTPPOST,cookieread)

This commented out HTTPPOST attempt is completely wrong.

> curl.setopt(pycurl.URL,'http://www.zope.org/Members/ABC/updateMember')
> dataupdate=urllib.urlencode({'full_name':'ABCS','company':'mvbvbv','email':'preetic_at_mahiti.org','submit':'Save
> Changes'})
> curl.setopt(pycurl.POSTFIELDS,dataupdate)
> curl.perform()

If you received cookies in your first request that should be used in this
second one, then curl will fix that for you automaticly.

If you switch on VERBOSE I bet you will see just that.

-- 
 Daniel Stenberg -- curl related mails on curl related mailing lists please
-------------------------------------------------------
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code=31
Received on 2002-07-31