CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
[SOLVED] modifying header of LWP request

 



baddy
New User


Jul 31, 2009, 8:13 AM

Post #1 of 2 (1081 views)
[SOLVED] modifying header of LWP request Can't Post

Hi, I am making a HTTP request to the Google Analytics API using LWP UserAgent. Here is a example of what I have so far that does work:



Code
    # create user agent object 
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# Create a request
my $req = HTTP::Request->new(POST => 'https://www.google.com/accounts/ClientLogin');
$req->content_type('application/x-www-form-urlencoded');
$req->content("accountType=GOOGLE&Email=$user&Passwd=$pass&service=analytics&source=companyName-applicationName-versionID");

# Pass request to the user agent and get a response back
my $res = $ua->request($req);


That is the initial request to get the token (which works fine). The problem I am having is their documentation says all future requests should have this in the header:


Code
Authorization: GoogleLogin auth=yourAuthToken


I am unsure how to edit the request header in LWP. I have tried $req->header('my string here') but that did not seem to work. Any ideas on how I might do this?


(This post was edited by baddy on Jul 31, 2009, 9:57 AM)


baddy
New User


Jul 31, 2009, 9:57 AM

Post #2 of 2 (1079 views)
Re: [baddy] modifying header of LWP request [In reply to] Can't Post

I ended up getting this figured out, below is the code that worked:


Code
    # create user agent object 
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

# add authorization to headers
my @headers = (Authorization => "GoogleLogin Auth=$token");

# request page
my $res = $ua->get("https://www.google.com/analytics/feeds/accounts/default", @headers);



(This post was edited by baddy on Jul 31, 2009, 9:59 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives