Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

REST::Client GET with custom http headers authentication

by tf (Initiate)
on Mar 21, 2013 at 16:57 UTC ( #1024791=perlquestion: print w/replies, xml ) Need Help??
tf has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am trying to send GET requests to REST application
that demands custom headers authentication.
I tried setting headers with both REST::Client and WWW::Mechanize
but keep getting 401 error code response
Same url/method/headers do work using wget and curl
Any ideas?

use REST::Client; my $url = "http://foo/bar"; my $client = REST::Client->new(); $client->addHeader('u', 'ADMIN'); $client->addHeader('p', 'ADMIN'); $client->GET($url); print $client->responseContent();

Replies are listed 'Best First'.
Re: REST::Client GET with custom http headers authentication
by McA (Priest) on Mar 21, 2013 at 18:32 UTC


    the only thing which comes to my mind at the moment is the following: In the depth of REST::Client headers are handled by HTTP::Headers. This module makes some "header sanitizing" which could cause your problem. Look here:

    #!/usr/bin/perl use warnings; use strict; use HTTP::Headers; my $h = HTTP::Headers->new; $h->header('Content-Type' => 'text/plain'); # set $h->header('u' => 'user'); $h->header('p' => 'password'); print $h->as_string, "\n";
    Your headers 'u' and 'p' are converted to uppercase.

    Just a guess. Besides of that: Custom headers should use the X-blabla-namespace, in your case e.g. X-u and X-p.


      Hi, Does this issue ever get resolved as i am hitting same error and looking for some resolution.
        Can you be more specific, what issue are you talking about? Which version of REST::Client do you have?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024791]
Approved by marto
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-12-15 05:25 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (416 votes). Check out past polls.