Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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?
Thanks!

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();

Comment on REST::Client GET with custom http headers authentication
Download Code
Re: REST::Client GET with custom http headers authentication
by McA (Priest) on Mar 21, 2013 at 18:32 UTC

    Hi,

    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.

    McA

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024791]
Approved by marto
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2015-07-03 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (54 votes), past polls