日语文本在传递到http restlet服务时被篡改

日语文本在传递到http restlet服务时被篡改,http,encoding,utf-8,request,Http,Encoding,Utf 8,Request,我有一个Perl客户端,它正在调用http restlet服务put方法。此调用中的某些参数包含日文文本。当我在restlet服务中打印这些请求参数的内容时,我发现这些字符乱码了 这是我的PERL客户端代码: my %request_headers = ( 'DocumentName' => $document_name, --> This name is a JAPANESE String 'DocumentDescription' => 'T

我有一个Perl客户端,它正在调用http restlet服务put方法。此调用中的某些参数包含日文文本。当我在restlet服务中打印这些请求参数的内容时,我发现这些字符乱码了

这是我的PERL客户端代码:

my %request_headers = (
        'DocumentName' => $document_name, --> This name is a JAPANESE String
        'DocumentDescription' => 'Test Japanese Chars',
        'content-length' => 200,
        'Content-Type' => 'application/octet-stream; charset=utf-8',
        'User-Agent' => "JPCharTester",
        );

        $s->write_request('PUT', '/test-document/TEST/TEST_DOCUMENT' , %request_headers, $content);
在这个调用中,$context和$document_name的值都是日文字符串。但在我的后端服务中,只有文档名称被接收为乱码

服务代码如下:

String URL_ENCODING = "UTF-8";
String documentName = requestHeaders.getFirstValue("DocumentName");
System.out.println("Encoded Document Name : "+documentName+" <<<"); --> documentName is garbled here

try {
    documentName = URLDecoder.decode(documentName, URL_ENCODING);
    System.out.println(>>> Decoded Document Name : "+documentName+" <<<"); --> documentName is garbled here
} catch (java.io.UnsupportedEncodingException ex) {
    throwException(ex.getMessage(), Status.SERVER_ERROR_INTERNAL, ex);
}
以上两个日志语句都打印了乱码

有人能告诉我我犯了什么错误以及如何纠正吗

提前感谢你的帮助

问候,, Satish.

不要忘记将客户端的数据编码为UTF-8。如果你说

'Content-Type' => 'application/octet-stream; charset=utf-8'
但这并不能神奇地解决问题。这只是一个提示,提示接收者以何种形式获取数据。您还必须以正确的格式发送。在perl中:

use utf8;
...
    'DocumentName' => utf8::encode($document_name),
...

... , utf8::encode($content) ...
可能重复的