【问题标题】:x-www-form-url-encoded POST Request not acceptedx-www-form-url-encoded POST 请求不被接受
【发布时间】:2021-01-04 02:41:08
【问题描述】:

我有一个使用 Postman 发送的 POST 请求,如下所示:

标题:

Content-Type: x-www-form-url-encoded
Content-Length: calculated when request is sent
Host: calculated when request is sent
User-Agent: PostmanRuntime/7.26.5
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: Keep-Alive

主体:

Key                 Value
---------------------------------------------
Value               ASDSFSDFDSFSDFSDFS..[ecc]

到目前为止,我能够将请求发送到 .jsp 构建,如下所示:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  ....

现在我想将这个POST Request 发送到Jersey REST Controller 到我的webapp; REST Controller 类似如下:

@Path("/api")
public class LoginResources {
  
  @POST
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Path("/login")
  public void logIn(HttpServletRequest request) {
    ...
  }    
}

因为这个错误,我没能做到这一点:

HTTP Status 415 – Unsupported Media Type

有什么想法吗??

【问题讨论】:

    标签: rest jersey http-status-code-415 x-www-form-urlencoded


    【解决方案1】:

    这样解决:

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces({MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON})
    @Path("/login")
    public void saml(MultivaluedMap paramMap) {
        Object valueObj = paramMap.get("Value");
        // remember to remove [] parentesis
        ...
    }
    

    希望有帮助..

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多