【问题标题】:Query parameters with Apache http post [duplicate]使用 Apache http post 查询参数 [重复]
【发布时间】: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


【解决方案1】:

将您的content-type 更改为application/x-www-form-urlencoded,并从正文中删除前导?

【讨论】:

  • 这成功了!非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 1970-01-01
  • 1970-01-01
  • 2013-02-06
  • 2023-03-30
相关资源
最近更新 更多