【发布时间】:2016-01-15 15:32:44
【问题描述】:
我刚开始使用 Jersey 框架,想使用 Jersey 客户端发送一个 HTTP 请求,并将 content-type 设置为 application/x-www-form-urlencoded。
以下两个选项会导致两个略有不同的请求。
// webTarget is a WebTarget instance, already configured
Form form = new Form();
form.param("some-string", "some string");
Response response1 = webTarget.request().header("Content-Type", "application/x-www-form-urlencoded").post(Entity.form(form));
Response response2 = webTarget.request(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(Entity.entity("some-string=some string, MediaType.APPLICATION_FORM_URLENCODED));
第一个选项生成的正文如下所示:
some-string=some+string
第二个选项生成的正文如下所示:
some-string=some string
为什么会有差异?他们应该不一样吗?
【问题讨论】:
标签: java http-headers jersey content-type url-encoding