Perl LWP :: useragent capture server response headers

I am requesting a web server for a document and I want to capture both the document and the related server response headers (e.g. Content-Type: ...). I'm having trouble reading the headers. Here are some sniplets from my Perl script, I left an error for checking:

use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent( 'requiredCustomUserAgent' ); # I'm required to set a custom user agent $imageData = $response->content; # This is the received document 

So, at this point I can get the web document, but I want to know what the Content-Type server sent with it. Unfortunately, this is not always the same as the mime type found by the bash 'file command. This file method fails with .js or .css documents.

+4
source share
1 answer

http://search.cpan.org/perldoc?HTTP::Response

 use LWP::UserAgent; my $ua = new LWP::UserAgent; my $response = $ua->get("http://google.co.uk"); print $response->headers()->as_string; print $response->header('content-type'); 
+13
source

Source: https://habr.com/ru/post/1401665/


All Articles