It feels strange to answer to myself. But here is an answer which describes the best my original problem.

  • It is not possible to transfer cookies between 'agents'. That means if you get cookie via curl, you cannot supply it back to JIRA/REST via LWP.
  • Use cURL to retrieve original cookie? Then continue with cURL. If you plan to use LWP or JIRA::Client::Automated, like me, get cookie via this agent. See following code:

    use LWP::UserAgent; use HTTP::Request; my $user = "JIRAusername"; my $password = "Lamepassword"; my $jira_url = "put_your_server_here"; my $ck=LWP::UserAgent->new( ); my $getline= $jira_url . '/jiraurl/rest/auth/1/session'; my $request = new HTTP::Request (GET => $getline, HTTP::Headers->new(' +Content_Type' => 'application/json') ); $request->authorization_basic($user, $password); my $answer = $ck->request ($request); my $cookie = $answer->header('Set-Cookie');
    The very last line gave me a lot of grey hair, so enjoy it, please. Now you have all cookies in variable. JIRA gives me normal 'JSESSION cookie' and token together. Authentication was NOT functional in case I have used only one of them.
  • Second pitfall - where and how to put cookie? I mean as a part of JIRA request.
  • Following piece of code is showing easy way to use it. I have created another lwp agent, just to show cookie is functional for independent one.
    my $ua=LWP::UserAgent->new( keep_alive => 1 ); my $key = 'existing_issue_code'; #this is just for test. You can use a +ny issue you get from web JIRA $getline=$url . '/rest/api/latest/issue/' . $key; $request = new HTTP::Request (GET => $getline, HTTP::Headers->new('Coo +kie'=> $cookie ) ); $answer = $ua->request ($request);
    Then just test return value, it shall be 200 and enjoy...

    I will spend some time by debugging of updated version of JIRA::Client::Automated and post it on CPAN later.


    In reply to Re: what is the correct way to set cookie in LWP::UserAgent by Eroln
    in thread what is the correct way to set cookie in LWP::UserAgent by Eroln

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.