【发布时间】:2019-02-08 11:08:22
【问题描述】:
我正在使用 Apache HTTP Components Client 4.5.7 请求包含双斜杠的 URL。当我查看电线日志时,我看到双斜线被“固定”为只有一个斜线。不幸的是,这对我来说不是可取的行为,因为它会导致请求失败。
背景:我正在从 Thumbor(图像大小调整服务器)请求调整大小的图像。 Thumbor URL 基本上如下所示:
此 URL 将导致 thumbor 下载 http://host.com/image.jpg 并调整其大小以适应 200x200 像素。
代码如下所示:
HttpGet httpUriRequest = new HttpGet("http://thumbors-server/usafe/200x200/http://host.com/image.jpg");
CLIENT.execute(httpUriRequest, responseHandler);
httpclient 发送到服务器的内容。然而这是:
DEBUG o.a.h.headers http-outgoing-1 >> GET /unsafe/300x300/http:/host.com/image1.jpg HTTP/1.1
DEBUG o.a.h.headers http-outgoing-1 >> Host: localhost:4002
DEBUG o.a.h.headers http-outgoing-1 >> Connection: Keep-Alive
DEBUG o.a.h.headers http-outgoing-1 >> User-Agent: Apache-HttpClient/4.5.7 (Java/11.0.1)
DEBUG o.a.h.headers http-outgoing-1 >> Accept-Encoding: gzip,deflate
请注意http://host.com 已替换为 http:/host.com(注意缺少的第二个 /)。这将导致请求失败。
如何阻止 http 客户端“修复”我传递给它的 url?
【问题讨论】:
标签: java apache-httpcomponents