0

我有一个使用 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 RequestJersey REST Controller我的 webapp;REST 控制器类似于以下内容:

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

由于这个错误,我没有设法做到这一点:

HTTP Status 415 – Unsupported Media Type

任何想法??

4

1 回答 1

0

以这种方式解决:

@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
    ...
}

希望有帮助..

于 2020-09-17T13:05:10.043 回答