简体   繁体   English

Jersey REST WS - 请求正文 UTF-8

[英]Jersey REST WS - request body UTF-8

I have simple Jersey REST webServices:我有简单的 Jersey REST 网络服务:

@POST
@Path("/label")
@Consumes(MediaType.TEXT_HTML)      
public Response setLabels(String requestBody) { 
    System.out.println(requestBody);
......
}

Request passes some text with "special" non-English characters请求传递一些带有“特殊”非英文字符的文本

 [{"За обекта"}]

I can see in Firebug that request passed with correct UTF-8 content and charset我可以在 Firebug 中看到请求以正确的 UTF-8 内容和字符集传递

Content-Type    text/plain; charset=UTF-8

Though on on server output does not present desirable charset:虽然在服务器 output 上没有提供理想的字符集:

  [{"?? ??????"}]

Any Idea what and were went wrong?有什么想法和出错了吗? How can I capture text in correct charset on server side?如何在服务器端以正确的字符集捕获文本?

System.out is a PrintStream . System.out是一个PrintStream It uses the platform default encoding, which is typically not UTF-8.它使用平台默认编码,通常不是 UTF-8。 So you are getting the correct data in, it's just getting mangled when you print it to the console.所以你得到了正确的数据,当你将它打印到控制台时它只是被破坏了。

I had the exact same problem a few weeks ago - drove me nuts until I figured it out.几周前我遇到了完全相同的问题 - 让我发疯,直到我弄清楚。 What made it worse is that I actually had an encoding-related bug in another part of the code.更糟糕的是,我实际上在代码的另一部分一个与编码相关的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM