Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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

Hi,

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);
0
mypatek
Asked:
mypatek
  • 5
  • 5
1 Solution
 
Adam314Commented:
Try
use Encode;

$in_name=encode("utf8", $in_name);
0
 
mypatekAuthor Commented:
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);

0
 
Adam314Commented:
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);

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mypatekAuthor Commented:
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
0
 
Adam314Commented:
Do you know what type of encoding is needed?
The Encode module can handle many encodings, see here:
http://search.cpan.org/~dankogai/Encode-2.23/Encode.pm

There are also other modules for other specific types of encoding.
0
 
mypatekAuthor Commented:
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?
0
 
Adam314Commented:
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.
0
 
mypatekAuthor Commented:
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.

i.e.

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

my $server =  'https://user:pw@xml.server.com/xml-rpc';
     
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



0
 
mypatekAuthor Commented:
is there a way to tell the xmlrpc handler that the data is submitted in UTF8?
0
 
Adam314Commented:
I'm not sure.  The server might not allow those characters.  If so, there is nothing you can do on the client side...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now