如何防止来自HttpsURLConnection的CONNECT方法调用

我有一个Android客户端向服务器发出HTTPS请求。 防火墙日志包含不需要的CONNECT请求方法的条目。

什么时候会发送CONNECT请求,如何防止它被发送? 我希望只有GET请求。 我的理解是,对openConnection()的调用实际上并没有发出请求,并且GET请求将继续调用getResponseMessage()。

如何禁用http客户端尝试建立代理隧道?

以下是我发送连接并拨打电话的方式:

URL url = new URL("https://some.server.com"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setConnectTimeout(CONNECT_TIMEOUT); connection.setReadTimeout(REAT_TIMEOUT); connection.setRequestProperty(ACCEPT_CHARSET, UTF8_CHARSET); connection.setRequestProperty(CONTENT_TYPE_HEADER, contentType); setCustomRequestProperties(connection); connection.setRequestMethod("GET"); //create response connection.getResponseMessage(); connection.getResponseCode(); connection.getContentType(); connection.getContent(); 

编辑:

这是我要阻止的防火墙日志条目:

 CONNECT someURL.domain.com:443 HTTP/1.1 Host: someURL.domain.com User-Agent: CustomUserAgent;1.0.0(Android 4.3;Nexus 4;T-Mobile) Proxy-Connection: Keep-Alive X-SSL-Secure: true X-CS-Source-IP: 10.3.3.3 X-Forwarded-For: 10.3.3.3 

我认为这是代理相关的,因为“代理连接”标题

URLConnection的默认设置是池化TCP(套接字)连接。 似乎“代理连接”标头具有误导性,因为当“连接”真正意图时,该标头可能被盗用。

当我设置系统属性

 System.setProperty("http.keepAlive", "false"); 

为了禁用连接池,CONNECT方法请求条目消失了。

由于需要为每个请求创建套接字,因此会有轻微的性能损失,但应用程序不会产生大量请求,因此这是可以接受的。

只有在配置了HTTP代理时才会发生这种情况。 可能你已经设置了系统属性http.proxyHosthttp.proxyPort,或者Android可能有另一种方法来配置它。