AnnShinoy has asked for the wisdom of the Perl Monks concerning the following question:

HI, I am setting a cookie in Perl using http header Set-Cookie= name=value; From this perl I am submitting a POST request to a dll which again sets some cookies using the same header as mentioned above. At the end while reading the cookies I am not able to see the cookie I set in the beginning. The variable I used in the beginning is unique and not used again for setting any other cookie variable. Is it because the dll replaces the cookie? If so is there any way I can avoid this?

Replies are listed 'Best First'.
Re: Cookies in Perl
by JavaFan (Canon) on Apr 19, 2012 at 10:15 UTC
    Your question is vague. What does "submit a POST request to a dll" mean? Is that something else than doing an HTTP request? And what do you mean by "set a cooking in Perl using http header Set-Cookie= name=value;"? Do you mean you print that line in the HTTP request? That would mean you're using the wrong syntax, as you should be using a colon instead of your first '=' character.

    Can you post some actual code (a small self-contained fragment, with all unrelevant pieces removed) explaining what you did, and what you get?

Re: Cookies in Perl
by Anonymous Monk on Apr 19, 2012 at 10:12 UTC
    One cannot follow this abstract explanation, you left out too many details. Any answer you will get must necessarily include a good deal of speculation.

    Show your code, so that we may reproduce the problem.

Re: Cookies in Perl
by locked_user sundialsvc4 (Abbot) on Apr 19, 2012 at 12:42 UTC

    I think that you need to do some online research to better understand exactly how cookies work in the HTTP protocol ... “for the moment, at least, ‘never mind Perl.’”   Don’t keep staring at that piece of code:   get the surrounding picture.   It will be very helpful for you to use a web-browser debugger, such as the Firebug add-on for Firefox or the built-in debuggers of IE or Opera, to allow you to watch the HTTP traffic that is actually passing between your machine and the server.   With these tools, you can see the content of the HTTP headers of both the request and the reply:   the set-cookie directives and the subsequent inclusion (or not... oops...) of the cookie value in subsequent exchanges.   Whether the data is being sent via GET or POST or both, “there it is ... what went out, and what came back ... ping and pong.”   Reset the browser and clear all cookies with each test (the debuggers provide this with a button-click).

    My educated guess is that the root cause of the problem won’t turn out to be “in the Perl code per se at all,” but rather in exactly how the code you’re looking at, and/or the code which surrounds it, is interacting with the server and thence with the client.   You might be looking at the right thing now, or you might be looking at a red herring.   No way to know yet, but you can find out.   The best way to identify exactly what is the bug that you are searching for, is, as I said, to watch the actual back-and-forth HTTP exchanges that the existing code is now producing; rightly or wrongly.   Once you can say, “there is the incorrect exchange,” you can find its root cause straight away in whatever source-code and/or configuration file it ultimately might turn out to be.   “You learn a lot by watching.”

    HTH ...

      Thanks a lot. The comments were an eye opener. I tried tracking the back and forth HTTP requests and responses. The domain was changing because of which the cookie value set in perl(in another domain) disappear. Making all domains the same resolved the issue