libwww-perl / WWW-Mechanize

Handy web browsing in a Perl object
https://metacpan.org/pod/WWW::Mechanize
Other
68 stars 53 forks source link

Is there an easy way to print the response? #233

Closed zorgnax closed 7 years ago

zorgnax commented 7 years ago

Is there a method, or can you add a method that will print the full text of the response in one go. Something like this:

print $m->response->status_line() . "\n" . $m->response->headers->as_string() . "\n" . $m->response->decoded_content() . "\n";
oalders commented 7 years ago

Have you tried LWP::ConsoleLogger? An easy way to get started is by adding:

use LWP::ConsoleLogger::Everywhere ();

That will give you lots of debugging output. You can pare it down from there. Check LWP::ConsoleLogger::Easy for more information.

zorgnax commented 7 years ago

I can dump the response myself with a very long line everytime I need it, I just think it belongs in WWW::Mechanize or HTTP::Response since there are a lot of other dump subroutines in there. kinda surprised this isn't one of them.

oalders commented 7 years ago

The method I pointed out works in both WWW::Mechanize and LWP::UserAgent. It's a short one-liner, so I don't see a lot of overhead in using it.

@petdance what do you think about adding another dump method to WWW::Mechanize?

petdance commented 7 years ago

I think that if you write a function that does print $m->response->status_line() . "\n" . $m->response->headers->as_string() . "\n" . $m->response->decoded_content() . "\n"; that then someone will want a version that doesn't include the status line, and someone else will want one that includes cookies only, and so on, and nobody nobody will be happy with it.

oalders commented 7 years ago

That seems like the logical outcome.

skaji commented 7 years ago

There is a dump method. https://metacpan.org/pod/HTTP::Message#$mess->dump(-%opt-)