Warren Humphreys
unread,Aug 14, 2017, 10:34:29 PM8/14/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mojol...@googlegroups.com
Hi,
I’m attempting to talk to a slightly unusual API using Mojo::UserAgent;
To authenticate I first have to post an XML payload, the response to which is another XML payload containing some cookies that I need to set to continue to talk to the API.
To be clear the cookie values come back in the response XML payload, they are not set as response cookies.
I can process the DOM just fine and extract the cookie values, but if I add them to the useragent cookie_jar before my next request the Cookie header isn’t set to contain the values in the jar.
So if I do this: -
POST request and get payload, then
my $coookies = '';
for my $cookie ($res—>dom—>find('cookie')—>each) {
$ua—>cookie_jar—>add(
Mojo::Cookie::Response—>new(
name => $cookie—>attr('name'),
domain => $cookie—>attr('domain'),
path => $cookie—>attr('path'),
value => $cookie—>text
)
);
$cookies .= $cookie—>attr('name');
$cookies .= '=';
$cookies .= $cookie—>text;
$cookies .= ';';
}
$tx = $ua—>post($APIURL => {Accept => 'application/json', 'Content—Type' => 'application/json', 'Cookie' => $cookies} => $request );
Manually including the Cookie header in the request works, anything else doesn’t.
I’m probably missing something obvious, but its driving me mad.