Submit strings with special chars (UTF-8) in an array through XML-RPC

Posted on 2007-10-09
Last Modified: 2009-07-29

I just faced the following problem:

If I make the following XML call with an array of names (@names) it works fine except the names contain special chars.

Working example: Miller, Tommen, Braun
Not working: Miller, Sülden, Braun (I get a http error / server error)

.. RPC::XML::struct->new( email => $in_email, language => $in_language, name=>\@names ));

The names should be submitted by XML RPC in UTF8 encoding. The users enter the name in a html form with the header "<meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta>"

Is it necessary to convert the input to UTF8 or is this already done by the html form with the respective header?

I've tried to convert the names before putting them into an array with the following to avoid the mentioned error. But no success: What exactly does this?

utf8::encode($in_name) if utf8::is_utf8($in_name);
Question by:mypatek
    LVL 39

    Accepted Solution

    use Encode;

    $in_name=encode("utf8", $in_name);

    Author Comment

    Hmm, unfortunately no success. I still get the following error:
    Problem: RPC::XML::Client::send_request: HTTP server error: Internal Server Error

    How should I add the strings to the array to avoid this error?

    Current way: push(@names,$in_firstname." ".$in_lastname);

    LVL 39

    Expert Comment

    You could change $in_firstname and $in_lastname before adding it to the array.
        $in_firstname=encode("utf8", $in_firstname);
        $in_lastname = encode("utf8", $in_lastname);

    Or change what is added to the array
        push(@names,encode("utf8", $in_firstname." ".$in_lastname));

    Or you could update the array after adding:
        $_=encode("utf8", $_) foreach (@names);


    Author Comment

    Thanks, but no change. still the same error while submitting..

    "Problem: RPC::XML::Client::send_request: HTTP server error: Internal Server Error"

    So we should forget the UTF thing.. I thought this would cause the error but as an utf encoded string contains also special chars the encoding itself cannot resolve the above mentioned http error.

    If I have the name: "Méndez Tony" in the string, the error occurs

    if I change the char "é" to e --> "Mendez Tony", the XML call works
    LVL 39

    Expert Comment

    Do you know what type of encoding is needed?
    The Encode module can handle many encodings, see here:

    There are also other modules for other specific types of encoding.

    Author Comment

    UTF8 format is requested by the remote server.

    If I pass the name with special chars as a single value ($name) to the remote server with the following procedure:
    RPC::XML::struct->new( name => $name ));
    no error shows up

    but submission of multiple values
    RPC::XML::struct->new( email => $in_email, language => $in_language, name=>\@names ));
    does not work if one name has special chars in it.

    So I don't think there is a problem with the data format

    Some months ago you recommended to use name=>\@names to submit multiple values to the remote xml server. I suppose if a http error is displayed, the call won't even reach the remote server and the error occurs on the local machine?? Is the array unpacked before the data is transmitted to the remote server?
    LVL 39

    Expert Comment

    I'm not sure how the data is actually sent to the server.  Can you access the server error logs?  They might help you figure out what the cause of the error is.

    Author Comment

    Sorry for the late reply..

    I checked my error log with "debug setting" but get no info. The error seems to occur on the remote server and I don't have access there to the errorlogs.

    But it seems to be definitely an encoding problem as the error occurs also with single value parameters, not only arrays.


    # my $name = "Rübe";
    my $name = "Rube";

    my $server =  '';
    my $cli = RPC::XML::Client->new($server, combined_handler => \&problems);

    my $req = RPC::XML::request->new('data.getNames', RPC::XML::struct->new( user_id => $user_id, name => $name ));

    my $resp = $cli->simple_request($req);

    "Rube" works; "Rübe" generates an error


    Author Comment

    is there a way to tell the xmlrpc handler that the data is submitted in UTF8?
    LVL 39

    Expert Comment

    I'm not sure.  The server might not allow those characters.  If so, there is nothing you can do on the client side...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now