Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to set charset when POSTing?

by vr (Curate)
on Jul 30, 2021 at 16:27 UTC ( [id://11135531]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found