in reply to how to validate lwp::useragent request?
$request->as_string() returns the request, headers and all. However, it needs to be called AFTER the UserAgent adds its headers. You can force UserAgent to add its headers by calling the UserAgent's prepare_request. To avoid calling prepare_request a second time, substitute a call to the UserAgent's send_request method for the call to the its request method.
In other words, replace
$response = $ua->request($request);
with
$ua->prepare_request($request); print($request->as_string); # $response = $ua->send_request($request);
Uncomment the commented line if you want to both log and send the request.
Similarly, get is just a shortcut to return a request object and passing it to the UserAgent's request method.
$response = $ua->get($url);
is the same thing as
$request = HTTP::Request::Common::GET($url); $response = $ua->request($request);
so replace it with
$request = HTTP::Request::Common::GET($url); $ua->prepare_request($request); print($request->as_string); # $response = $ua->send_request($request);
|
|---|