我正在关注 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/