in reply to Re^3: Error "HTTP::Message content must be bytes" while posting with LWP
in thread Error "HTTP::Message content must be bytes" while posting with LWP

I had this problem and went through the tedious exercise of understanding unicode, utf-8 etc all over again. Basically the developer of LWP has enforced that strings sent to HTTP::Message - and therefore all the higher functions such as parse to be octet based - as it is in the natural environment of the web. So this means that generating raw html strings in perl and expecting HTTP::Response parsing to work will fail (because Perl uses native utf8 and the module doesn't. This is pretty annoying I know as you assume you shouldn't have to encode perl strings internally - but thats how it is. The easy fix is to force your homemade html strings to be byte based thus:
use Encode; use HTTP::Response; my $internal_html = my_html_generation_function(); my $enc_html = encode("iso-8859-1",$internal_html); #for the respons +e object to manage in octets; my $response = HTTP::Response->parse($enc_html);
  • Comment on Re^4: Error "HTTP::Message content must be bytes" while posting with LWP
  • Download Code