Setting cookies

46 views
Skip to first unread message

Warren Humphreys

unread,
Aug 14, 2017, 10:34:29 PM8/14/17
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.


Warren Humphreys

unread,
Aug 29, 2017, 3:46:44 PM8/29/17
to mojol...@googlegroups.com
Bump.

Am I creating cookies correctly?

Cheers,

Warren
> --
> You received this message because you are subscribed to the Google Groups "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages