Java restlet post getFirstValue始终返回null

Java restlet post getFirstValue始终返回null,java,rest,jax-rs,restlet,Java,Rest,Jax Rs,Restlet,我正在使用postman客户端向这个不安的路由器发送RES请求: public Representation createAgent(Representation entity) { Form form = new Form(entity); String user = form.getFirstValue("user"); String password = form.getFirstValue("password"); System.out.printl

我正在使用postman客户端向这个不安的路由器发送RES请求:

public Representation createAgent(Representation entity) {
    Form form = new Form(entity);

    String user = form.getFirstValue("user");
    String password = form.getFirstValue("password");


    System.out.println("user: "+ user);
    System.out.println("password: "+ password);
    System.out.println("form: "+ form.toString());

    return (agent.save(getUser(),getPassword()))
            ? new StringRepresentation("user "+ user +" created", MediaType.TEXT_PLAIN)
            : new StringRepresentation("agent creation failed",MediaType.TEXT_PLAIN);

}
Usera和password始终为空,尽管打印form.toString()时显示:

以下是预览模式下的完整邮递员请求:

POST /v1/agents HTTP/1.1
Host: localhost:9000
Authorization: Basic c2NvdHQ6amRmZ2pkZnRnaA==
Cache-Control: no-cache
 Postman-Token: ef58fda2-8974-0d9f-7a23-10c94df8552e
 Content-Type: multipart/form-data; boundary=----                        WebKitFormBoundary7MA4YWxkTrZu0gW

 ----WebKitFormBoundary7MA4YWxkTrZu0gW
  Content-Disposition: form-data; name="user"

 ali
 ----WebKitFormBoundary7MA4YWxkTrZu0gW
  Content-Disposition: form-data; name="password"

  dsndfjo32
 ----WebKitFormBoundary7MA4YWxkTrZu0gW

事实上,如果查看在请求中发送的数据的内容类型,这对应于多部分内容,而不是URL编码的表单

您在服务器资源中使用的代码仅适用于URL编码的表单(内容类型
application/x-www-form-urlencoded
)。所以你什么都得不到是正常的。作为参考,这种方法的有效载荷如下:

user=my+user&password=my+password
也许这是你想要的东西。如果是,请选择邮递员内的选项卡
x-www-form-urlencoded

当您希望上载包含其他数据的文件时,通常使用Multipart。如果多部分是您想要的,您应该查看以下链接:

希望它能帮助你, 蒂埃里

user=my+user&password=my+password