我正在使用 Jersey 2.4.1
我不知道。为什么post提交时无法添加参数。我认为参数信息应该打印在第 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
最佳答案
要将表单参数打印到控制台日志,您需要使用默认构造函数以外的其他构造函数实例化 LoggingFilter
,请参阅 LoggingFilter(java.util.logging.Logger, boolean) :
client.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
此行为可能与 Jersey 1.x 中的行为不同。
关于java - Jersey 在 post 提交时无法添加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330577/