简体   繁体   English

如何获得RESTeasy方法来正确使用UTF-8编码的application / x-www-form-urlencode?

[英]How can I get a RESTeasy method to consume application/x-www-form-urlencoded as UTF-8 correctly?

I am using 我在用

curl --data-binary "content=abcdeöäüabcde" http://myserver.com/application/api -H "Content-Type: application/x-www-form-urlencoded; encoding=utf-8"

to POST form data to my web server. POST表单数据到我的Web服务器。

On server side I want to decode the content: 在服务器端,我想解码内容:

@POST
@Path("/api")
@Consumes("application/x-www-form-urlencoded")
public void createNote(@FormParam("content") String content){
    System.out.println(content);
}

The result is abcde???abcde 结果是abcde???abcde

Does anybody know how I can tell this method to consume the form parameters as UTF-8? 有人知道我如何告诉该方法将表单参数作为UTF-8使用吗?

尝试:

byte[] encoded = content.getBytes("UTF-8");

It seems that cURL isn't able to process UTF-8 encoded Strings in POST requests at all. 似乎cURL根本无法处理POST请求中的UTF-8编码的字符串。 Converting the string to latin1 fixed my problem. 将字符串转换为latin1解决了我的问题。

暂无
暂无

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

相关问题 Spring Boot - 不支持内容类型“application/x-www-form-urlencoded;charset=UTF-8” - Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 如何使用application / x-www-form-urlencoded运行jmeter请求; charset = UTF-8“(像邮差的)设置 - How to run jmeter requests with application/x-www-form-urlencoded; charset=UTF-8" (like postman's) setting restcontroller和application / x-www-form-urlencoded; charset = UTF-8媒体类型的问题 - Issue with restcontroller and application/x-www-form-urlencoded;charset=UTF-8 media type 内容类型 'application/x-www-form-urlencoded;charset=UTF-8' 不支持 - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported Resteasy设置表单网址编码的x-www-form-urlencoded - Resteasy to set form url encoded x-www-form-urlencoded "status":415, "status":"UNSUPPORTED_MEDIA_TYPE","message":"内容类型 'application/x-www-form-urlencoded;charset=UTF-8' 不支持 - "status":415, "status":"UNSUPPORTED_MEDIA_TYPE","message":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 如何以 application/x-www-form-urlencoded 在 restTemplate 中发送正文 - How to send body in restTemplate as application/x-www-form-urlencoded 如何使用关联数组解析 application/x-www-form-urlencoded? - How to parse a application/x-www-form-urlencoded with an associative array? 如何确定 Microprofile RestClient 中 x-www-form-urlencoded 的参数顺序? - How can I determine the order of parameters for x-www-form-urlencoded in Microprofile RestClient?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM