帖子提交时泽西不能添加参数

时间:2013-12-02 14:23:55

标签: java api rest jersey

我正在使用Jersey 2.4.1

我不知道。为什么我在发帖后无法添加参数。

参数信息应该在我认为的第5行打印。

我的示例代码位于

之下
@Test
public void test() {
    Client client = ClientBuilder.newClient();
    client.register(new LoggingFilter());
    WebTarget target = client.target("http://stackoverflow.com/");

    Form form = new Form();
    form.param("x", "foo");
    form.param("y", "bar");

    target.request(MediaType.APPLICATION_JSON_TYPE)
        .post(Entity.form(form));
}

结果记录是..

1 * LoggingFilter - Request received on thread main
1 > POST http://stackoverflow.com/
1 > Accept: application/json
1 > Content-Type: application/x-www-form-urlencoded

2 * LoggingFilter - Response received on thread main
2 < 200
2 < X-Frame-Options: SAMEORIGIN
2 < Date: Mon, 02 Dec 2013 14:13:35 GMT
2 < Vary: *
2 < Content-Length: 195990
2 < Expires: Mon, 02 Dec 2013 14:14:35 GMT
2 < Last-Modified: Mon, 02 Dec 2013 14:13:35 GMT
2 < Content-Type: text/html; charset=utf-8
2 < Pragma: no-cache
2 < Cache-Control: public, max-age=60

1 个答案:

答案 0 :(得分:2)

要将表单参数打印到控制台日志,您需要使用除默认值之外的其他构造函数来实例化LoggingFilter,请参阅LoggingFilter(java.util.logging.Logger, boolean)

client.register(new LoggingFilter(Logger.getAnonymousLogger(), true));

此行为可能与Jersey 1.x中的行为不同。