cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Problem with cookie

From: Mandar Wadekar <MandarW_at_HeyAnita.com>
Date: Thu, 11 Apr 2002 11:09:38 -0700

Daniel, I really appreciate your instant response. Here is the info you
asked.

> OS : Win NT 4
> Compiler : MSVC++ 6.0
> CURL version : 7.9.5
>
> Here is my code :

[ cut out]

> All I am doing is enabling cookie-parser. I can even see the cookie
> received, being saved in cookie.ck file, for the first request. For
the
> next request, cookie would be automatically sent. But that does not
happen.
> After setting VERBOSE, curl spits out the header that is being sent.
But I
> do not see the cookie being sent. I even tried using CURLOPT_COOKIE
option,
> by setting the cookie myself. The result was worst. The server
rejected the
> request (Response from server : Malformed syntax).
>
> Am I obviously missing something here? I would really appreciate if I
get
> some pointers.

Showing some real-world data to us would help a lot here (edit out
sensitive
info first).

- What cookies are received in the first request? (Showing both headers
and
  the cookiejar)
- What URL is the second one?
- What does the second request look like?

- How did you use CURLOPT_COOKIE since it created a "malformed" request?

The First URL was like this :
http://servername/appserver/isapi.dll?application?mn_mainmenu.havbmainme
nuclass&HASW&ANI123&DNIS123d&CALLERID123&undefined
The Second URL would be something like
http://servername/appserver/isapi.dll?RespondToApp?XYZ=abc&TYP=def

To use CURLOPT_COOKIE, I read the cookie.ck file which was generated by
first request, stripped off the name,value pair from the cookie file and
the code looks like following :

/////////////////////////////////////////////////////My
Code/////////////////////////////////////////////////
                                char *cookieFileName =
"c:\\cookie-jar\\cookie.ck" ;
                                curl_easy_setopt(curl,CURLOPT_COOKIEJAR,
cookieFileName );
        
curl_easy_setopt(curl,CURLOPT_COOKIEFILE, cookieFileName );

#ifdef _FORCE_COOKIE_
                                _ReadCookie(); //this strips the cookie
value from cookie.ck file generated in first request.
                                strcpy(szCookie,"AppServerSyncFile=");
                                strcat(szCookie,szCookieValue);
                                strcat(szCookie,";");
                                res = curl_easy_setopt(curl,
CURLOPT_COOKIE, szCookie);

#endif
                                res = curl_easy_perform(curl);

 
                                curl_easy_cleanup(curl);
/////////////////////////////////////////////////////Code
End/////////////////////////////////////////////////

BTW, if you do two requests in a row like that, you're better off *not*
doing
cleanup and init again between the requests but instead just re-use the
same
handle...

Well, the requests are not in *row* actually. I have tried the same code
on Unix (ofcourse with Unix version of library) and it works perfect
(without _FORCE_COOKIE). It gives me a feeling that windows library
behaves in different manner.

-Mandar Wadekar
Received on 2002-04-11