Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 834925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:44:45+00:00 2026-05-15T04:44:45+00:00

I want to post russian text on a CP1251 site using LWP::UserAgent and get

  • 0

I want to post russian text on a CP1251 site using LWP::UserAgent and get following results:

# $text="Русский текст"; obtained from command line
FIELD_NAME => $text                                # result: Г?в г'В?г'В?г'В?г?вєг?вёг?в? Г'В'Г?вчг?вєг'В?г'В'
$text=Encode::decode_utf8($text);
FIELD_NAME => $text                                # result: Р с?с?с?рєрёр? С'Рчрєс?с'
FIELD_NAME => Encode::encode("cp1251", $text)     # result: Г?гіг+г+гЄгёгЏ ГІгҐгЄг+гІ
FIELD_NAME => URI::Escape::uri_escape_utf8($text) # result: D0%a0%d1%83%d1%81%d1%81%d0%ba%d0%b8%d0%b9%20%d1%82%d0%b5%d0%ba%d1%81%d1%82

How can I do this? Content-Type must be x-www-form-urlencoded. You can find similar form here, but there you can just escape any non-latin character using &#…; form, trying to escape it in FIELD_NAME results in 10561091108910891 10901077108210891 (every &, # and ; stripped out of the string) or 1056;усский текст (punctuation characters at the beginning of the string are stripped out) depending on what the FIELD_NAME actually is.

UPDATE: Anybody knows how to convert the following code so that it will use LWP::UserAgent::post function?

my $url=shift;
my $fields=shift;
my $request=HTTP::Request->new(POST => absURL($url));
$request->content_type('application/x-www-form-urlencoded');
$request->content_encoding("UTF-8");
$ua->prepare_request($request);
my $content="";
for my $k (keys %$fields) {
    $content.="&" if($content ne "");
    my $c=$fields->{$k};
    eval {$c=Encode::decode_utf8($c)};
    $c=Encode::encode("cp1251", $c, Encode::FB_HTMLCREF);
    $content.="$k=".URI::Escape::uri_escape($c);
}
$request->content($content);
my $response=$ua->simple_request($request);

This code actually solves the problem, but I do not want to add the third request wrapper function (alongside with get and post).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:44:45+00:00Added an answer on May 15, 2026 at 4:44 am

    These functions solve the issue (first for posting application/x-www-form-urlencoded data and second for multipart/form-data):

    #{{{2 postue
    sub postue($$;$) {
        my $url=shift;
        my $fields=shift;
        my $referer=shift;
        if(defined $referer and $referer eq "" and defined $fields->{"DIR"}) {
            $referer=absURL($url."?DIR=".$fields->{"DIR"}); }
        else {
            $referer=absURL($referer); }
        my $request=HTTP::Request->new(POST => absURL($url));
        $request->content_type('application/x-www-form-urlencoded');
        $request->content_encoding("UTF-8");
        $ua->prepare_request($request);
        my $content="";
        for my $k (keys %$fields) {
            $content.="&" if($content ne "");
            my $c=$fields->{$k};
            if(not ref $c) {
                $c=Encode::decode_utf8($c) unless Encode::is_utf8($c);
                $c=Encode::encode("cp1251", $c, Encode::FB_HTMLCREF);
                $c=URI::Escape::uri_escape($c);
            }
            elsif(ref $c eq "URI::URL") {
                $c=$c->canonical();
                $c=URI::Escape::uri_escape($c);
            }
            $content.="$k=$c";
        }
        $request->content($content);
        $request->referer($referer) if(defined $referer);
        my $i=0;
        print STDERR "Doing POST request to url $url".
            (($::o_verbose>2)?(" with fields:\n".
                    ::YAML::dump($fields)):("\n"))
            if($::o_verbose>1);
      REQUEST:
        my $response=$ua->simple_request($request);
        $i++;
        my $code=$response->code;
        if($i<=$o_maxtries and 500<=$code and $code<600) {
            print STDERR "Failed to request $url with code $code... retrying\n"
                if($::o_verbose>2);
            sleep $o_retryafter;
            goto REQUEST;
        }
        return $response;
    }
    #{{{2 postfd
    sub postfd($$;$) {
        my $url=absURL(shift);
        my $content=shift;
        my $referer=shift;
        $referer=absURL($referer) if(defined $referer);
        my $i=0;
        print STDERR "Doing POST request (form-data) to url $url".
            (($::o_verbose>2)?(" with fields:\n".
                    ::YAML::dump($content)):("\n"))
            if($::o_verbose>1);
        my $newcontent=[];
        while(my ($f, $c)=splice @$content, 0, 2) {
            if(not ref $c) {
                $c=Encode::decode_utf8($c) unless Encode::is_utf8($c);
                $c=Encode::encode("cp1251", $c, Encode::FB_HTMLCREF);
            }
            push @$newcontent, $f, $c;
        }
      POST:
        my $response=$ua->post($url, $newcontent,
                               Content_type => "form-data",
                               ((defined $referer)?(referer => $referer):()));
        $i++;
        my $code=$response->code;
        if($i<=$o_maxtries and 500<=$code and $code<600) {
            print STDERR "Failed to download $url with code $code... retrying\n"
                if($::o_verbose>2);
            sleep $o_retryafter;
            goto POST;
        }
        return $response;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to post some text data to my Facebook fans page from my
i want to post dynamically generated multiple text box using php by foreach loop.
I want to POST an URL using CURL and php. There is a big
I have an ASP.NET application in which i want to post data using jQuery
I want to ignore the post form in the django's internatonalization. I am using
I want to post entries in my blogspot blog using php. But i just
I want to post an event to a facebook group using the graph API
Query: SELECT * FROM Post ORDER BY Post.rating <-- Here , i want (
I want to post on wall using fb API, When I post a message,
I want to post on wall using fb API, When I post a message,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.