简体   繁体   English

HTTPS 通过 HTTP 代理

[英]HTTPS through HTTP proxy

I have service which works like a proxy, you can get web pages through it.我有一个像代理一样工作的服务,你可以通过它获取网页。 For example via telnet例如通过 telnet

GET http://example.com HTTP/1.1
Host: example.com

But if I want download https page I should do the following但如果我想下载 https 页面,我应该执行以下操作

GET https://example.com HTTP/1.1
Host: example.com
Https-Header: true

And I want to write scala client for this service using apache http client, using service like a proxy host.我想使用 apache http 客户端为这个服务编写 Scala 客户端,使用像代理主机这样的服务。

private val DefaultProxy = new HttpHost("service host", port)
private val DefaultClient =
HttpClientBuilder.create().
  setProxy(DefaultProxy).
  build()

I can successfully download http pages, but when I try to download https pages, apache client makes CONNECT request to the proxy, and it response with error, cause service can operate only with GET requests.我可以成功下载http页面,但是当我尝试下载https页面时,apache客户端向代理发出CONNECT请求,并且响应错误,导致服务只能使用GET请求运行。 How can I make apache client work with https pages like with http, that's mean send GET request to proxy, not CONNECT?如何让 apache 客户端像使用 http 一样使用 https 页面,这意味着将 GET 请求发送到代理,而不是 CONNECT?

To download an https webpage in the same way than an http one with telnet you need to establish the ssl/tls connection first:要以与使用 telnet 下载 http 网页相同的方式下载 https 网页,您需要先建立 ssl/tls 连接:

openssl s_client -connect www.somesite:443 openssl s_client -connect www.somesite:443

[watch the ssl certificate details scroll by] [观看 ssl 证书详细信息滚动]

GET /index.html HTTP/1.1获取 /index.html HTTP/1.1

Host: www.somesite主机:www.somesite

Example from https://www.bearfruit.org/2008/04/17/telnet-for-testing-ssl-https-websites/示例来自https://www.bearfruit.org/2008/04/17/telnet-for-testing-ssl-https-websites/

For scala maybe that can help you : https://github.com/scalaj/scalaj-http对于 Scala,也许可以帮助您: https : //github.com/scalaj/scalaj-http

HTTPS is HTTP over SSL/TLS so you need something to establish the SSL/TLS secure tunnel to the website, then you can send your HTTP request. HTTPS 是基于 SSL/TLS 的 HTTP,所以你需要一些东西来建立到网站的 SSL/TLS 安全隧道,然后你可以发送你的 HTTP 请求。

I find out a solution.我找到了解决办法。

I write custom HttpRoutePlanner which always provide not secure route, and then Apache client work with https link like with http link, there is a HttpRoutePlanner code我编写了始终提供不安全路由的自定义 HttpRoutePlanner,然后 Apache 客户端像使用 http 链接一样使用 https 链接,有一个 HttpRoutePlanner 代码

private def routePlanner(proxy: HttpHost) = new HttpRoutePlanner() {

  def determineRoute(target: HttpHost ,
                     request: HttpRequest,
                     context: HttpContext) = {
    new HttpRoute(target, null,  proxy, false)
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM