in reply to what is the correct way to set cookie in LWP::UserAgent
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:
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.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');
Then just test return value, it shall be 200 and enjoy...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);
I will spend some time by debugging of updated version of JIRA::Client::Automated and post it on CPAN later.
|
|---|