perl: useragent - need to remove all headers from GET

Posted on 2004-04-28
Last Modified: 2008-03-06
I need to get only the content of the file I'm getting, I don't want any headers.

Example, although this doesn't seem to work:

$ua = LWP::UserAgent->new;
$request = HTTP::Request->new('GET',$url);
$request->authorization_basic($username_server, $password_server);
$data = $response->content()->as_string;

Any help would be much appreciated.

Thank you very much.

Best regards,

Question by:dr34m3rs

Assisted Solution

pillaib earned 83 total points
ID: 10937192
Hi Friend,

I got something from Google...

Try this,

Good Luck,
LVL 18

Accepted Solution

kandura earned 84 total points
ID: 10937371
$data = $response->content;
should give you only the body of the response, not the headers.

Maybe you should check whether the request was successful:

# check the outcome
  if ($response->is_success) {
     print $response->content;
  else {
     print "Error: " . $response->status_line . "\n";

LVL 20

Assisted Solution

jmcg earned 83 total points
ID: 10939464
It looks like you left out the line that actually performs the GET request and puts the result in $response.

my $response = $ua->request( $request);


Author Comment

ID: 10942156
Hey thank you for your responses. I went another way and went through the POST method. That worked great. But for the future all your answers helped, so I am going to split the points.

Thank you everyone :)


Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now