【问题标题】:Spring - wrong encoding POST request with x-www-form-urlencodedSpring - 使用 x-www-form-urlencoded 错误编码 POST 请求
【发布时间】:2019-02-28 11:43:08
【问题描述】:

我正在尝试构建一个带有一个参数的 POST(带有 x-www-form-urlencoded 标头)的应用程序。 这是我的 POST 方法代码:

@RequestMapping(value = "/translate", method = RequestMethod.POST)
public String getTranslate(@RequestParam("text") String text) {
     //................      
}

当我通过 Postman 使用 getTranslate 方法中的数据“让我们测量”(下图)发出 POST 请求时,文本值是“让我们测量”。 我做错了什么?

【问题讨论】:

  • 如果我的回答可以帮助您解决问题,那么请接受这个答案,这将有助于其他人获得确切的解决方案。

标签: java spring spring-mvc


【解决方案1】:

我猜你错过了在请求的标头中添加编码 - 只需添加内容类型和编码并尝试:

Content-Type:application/x-www-form-urlencoded;charset=UTF-8

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 2018-10-19
    相关资源
    最近更新 更多