【发布时间】:2018-10-23 19:05:25
【问题描述】:
我正在尝试访问一个 API,该 API 通过 Apache http 帖子返回带有查询参数的 Json 内容。端点在浏览器上运行良好,但我的发布请求完全忽略了查询参数。它在浏览器上运行良好。
HttpPost post = new HttpPost(url);// http://hostname:port/type/endpoint1
post.addHeader("content-type","text/plain");
post.addHeader("Accept","text/plain");
post.setEntity(new StringEntity("?key=value"));
response = client.execute(post);
这仅返回 url 的响应。并且完全忽略了参数。
【问题讨论】:
-
这是否意味着您希望拥有包含此内容的 HTTP 正文
post.setEntity(new StringEntity("?key=value")) -
@Berger 我的理解是关于服务器接受 JSON 的链接问题,而这个问题是关于服务器通过 POST 接受查询参数的问题。
标签: java http-post apache-httpcomponents