http://qs1969.pair.com?node_id=11135531


in reply to How to set charset when POSTing?

Found it. Previous WWW::Mechanize solution works OK because forms, there, are encoded wholesale, each and every name and value, regardless. See 455-457.

With new Net::Async::HTTP code, I was trying to be smart, only encoding those text values which obviously require to be encoded. However, another value, a string, simple uid in hexadecimal, sneaked in, which happens to be utf8::upgraded. Then URI module (used by HTTP::Request::Common) produces the whole url-encoded form data in utf-8, as I understand. I don't know if it's expected and documented behaviour, but it's not what server, processing my forms, understands. So solution is to always loop through and encode everything, as in 455-457 lines mentioned.

use strict; use warnings; use utf8; use feature 'say'; use URI; use Encode 'encode'; use charnames 'cyrillic'; my $uri = URI-> new( 'http:' ); my $ascii_uid_str = 'abc'; # whatever ascii my $high_ascii_octets = encode( 'koi8-r', qq(\N{zhe})); # = chr 214; # (same as above) # whatever, too, but high-ascii $uri-> query_form( $ascii_uid_str, $high_ascii_octets ); say $uri-> query; utf8::upgrade( $ascii_uid_str ); # oops, unexpected $uri-> query_form( $ascii_uid_str, $high_ascii_octets ); say $uri-> query; __END__ abc=%D6 abc=%C3%96