java - 带 SSL 的 Jetty HTTP 客户端

标签 java https

我正在关注 Jetty HttpClient Example ,但我无法使 SSL 连接正常工作。当我使用代理连接时,它会抛出“未实现”异常。当我不使用代理时,它不会返回任何内容。

HttpClient client = new HttpClient();
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
client.setProxy(new Address("www.example.com", 80));
client.start();

// create the exchange object, which lets you define where you want to go
// and what you want to do once you get a response
ContentExchange exchange = new ContentExchange()
{
  // define the callback method to process the response when you get it
  // back
  protected void onResponseComplete() throws IOException
  {
    super.onResponseComplete();
    String responseContent = this.getResponseContent();

    // do something with the response content
    System.out.println(responseContent);
  }
};

exchange.setMethod("GET");
exchange.setURL("https://www.example.com");
exchange.setScheme(HttpSchemes.HTTPS_BUFFER);

// start the exchange
client.send(exchange);
exchange.waitForDone();
System.err.println("Response status: " + exchange.getResponseStatus());

最佳答案

jetty v7.4.1:

if (dest.isSecure()) {
    if (dest.isProxied()) {
        SSLEngine engine=newSslEngine(channel); ep = new ProxySelectChannelEndPoint(channel, selectSet, key, _sslBuffers, engine, (int)_httpClient.getIdleTimeout());
    } else { ...

关于java - 带 SSL 的 Jetty HTTP 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1003187/

相关文章:

java - 使用 Commons-logging 设置日志写入方式

java - 关于 null 的 Comparable 和 Comparator 契约(Contract)

javascript - 如何在 node.js 中发起 https 请求

Tomcat SSL 实现未在浏览器中显示证书链

Java MySQL 执行更新 SQLSyntaxErrorException

java - 捕捉桌面图像

java - 通过 Method.invoke() 的静态方法调用给了我 NPE

http - 浏览器是否会根据协议(protocol)改变缓存内容?

php - 将所有请求重定向到非 www ssl https

ruby-on-rails - Rails redirect_to 从 https(正确)重定向到 http(不正确)?