#!/usr/bin/env perl -w use strict; use warnings; use LWP; my $outgoing_headers = ''; sub LWP::Protocol::http::Socket::format_request { return main::format_request(@_); } sub LWP::Protocol::https::Socket::format_request { return main::format_request(@_); } sub format_request { my( $socket, $method, $fullpath, @h ) = @_; my $req_buf = $socket->Net::HTTP::Methods::format_request($method, $fullpath, @h); $outgoing_headers = $req_buf; return $req_buf; } my $ua = new LWP::UserAgent; my $response = $ua->get("http://example.com"); #my $response = $ua->get("https://google.com"); warn "[Headers Out Real]\n", $outgoing_headers, "\n\n"; warn "[Headers Out]\n", $response->request()->as_string(), "\n\n"; warn "[Headers In]:\n", $response->headers()->as_string, "\n\n";