For any text in headers, you are best of with sticking to ISO-8859-1. For content, you have to mark that as UTF-8. Most likely, you want:

Content-Type: application/json; charset=utf-8

Depending on the content type, that charset may or may not also be marked within the content by the unicode mark at the beginning of the "file".

If the charset is not specified, most useragents will assume ISO-8859-1, according to HTTP spec. But some may infer other charsets, depending on things like the language header. Important here to note is that, while your request can specify any header you like, the server isn't really obligated to adhere to most of them. And the client will usually ignore all the headers you sent to the server and will only work on the headers that the server has sent back to you in the response.

For example, you set a 'Content-Type' request header. This is NOT a valid header. (Well, technically, it is valid HTTP, but it is ignored by servers because it's not in the spec as a client request header). The Content-Type header is a response header only, unless i seriously misremember the RFCs. The content type is set by the server and there is no in-header way to specify the charset the client wants.

For JSON, your best bet would probably to shove it through the JSON decoder library of your choice, hope it gets decoded correctly and then put it into your logger.

I haven't player with LWP::ConsoleLogger::*, but best bet is that it gets confused by a missing charset=utf-8 declaration or something. Most JSON modules on CPAN on the other hand make the mostly sensible choice of assuming that everything is UTF-8, because that's the same assumption JavaScript in most modern browsers would also make.

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP

In reply to Re: LWP::ConsoleLogger::Easy messes the console on (seemingly) unicode LWP response: is it a case of broken unicode? by cavac
in thread LWP::ConsoleLogger::Easy messes the console on (seemingly) unicode LWP response: is it a case of broken unicode? by bliako

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.