x-www-form-url-encoded POST Request not accepted

362 Views Asked by At

I have a POST Request sent with Postman as follows:

Headers:

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

Body:

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

Until now I was able to send the request to a .jsp build as follows:

<%@ 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">
  ....

Now I want to send this POST Request to a Jersey REST Controller to my webapp; the REST Controller is similar to follows:

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

I didn't manage to do this because of this error:

HTTP Status 415 – Unsupported Media Type

Any idea??

1

There are 1 best solutions below

0
On

Solved this way:

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

Hope helps..