Translating HTML template files

Currently I’ve been using use HTML::TokeParser; to break my templates and extract pure text. However I thought it would be easier (for me!) to try:

   my $res = $ua->request(
        'POST' => 'https://libretranslate.com/translate_file',
        {
            headers => {
                'Accept'     => '*/*',
                'User-Agent' => 'curl/7.55.1',

                #  'Content-Length' => '39',
                'Content-Type' => 'application/x-www-form-urlencoded'
            },
            content =>
"q=$file&source=en&target=$language&format=html&api_key=xxxxxxx"
        },
    );

and process a complete file in one go. This returns a 400. So, have I made a mistake or isn’t this possible? The intermediate idea is that I retain the parser but don’t go right down to text, just translate HTML fragments.