如何从HttpsURLConnection的prevent CONNECT方法调用 [英] How to prevent CONNECT method call from HttpsURLConnection

查看:211
本文介绍了如何从HttpsURLConnection的prevent CONNECT方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android客户端使HTTPS请求到服务器。防火墙日志​​的条目这是不希望CONNECT请求方法。

I have an Android client making HTTPS request to a server. The firewall logs have entries for CONNECT request methods which are not desired.

在将连接请求被发送出去了,我怎么能prevent它被发送?我只希望一个GET请求。我的理解是调用的openConnection()并不能使一个请求和GET请求会去调用getResponseMessage()。

When would the CONNECT request get sent out and how can I prevent it from being sent? I expect only a GET request. My understanding is that the call to openConnection() does not actually make a request and that the GET request would go on the call to getResponseMessage().

如何从试图建立一个隧道代理禁用HTTP客户端?

How can I disable the http client from attempting to establish a proxy tunnel?

下面是我送我的连接,并拨打电话:

Here is how I sent up my connection and make the call:

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();

编辑:

下面是我试图prevent防火墙日志​​条目:

Here is the Firewall Log entry that I am trying to prevent:

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

我认为这是因为代理服务器的连接头相关代理

I thought this was proxy related because of the "Proxy-Connection" header

推荐答案

有关的URLConnection默认是汇集TCP(插座)连接。看来, - 代理连接头被误导,因为在连接是真的打算这个头可以挪用。

The default for URLConnection is to pool the TCP (socket) connections. It seems that the "Proxy-Connection" header was misleading as that header can be misappropriated when "Connection" is really intended.

当我设置系统属性。

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

禁用连接池,CONNECT方法请求项就走了。

to disable the connection pool, the CONNECT method request entries went away.

有一个轻微的性能损失,因为套接字需要为每个请求创建,但应用不作要求的显著号码,这是可以接受的。

There is a slight performance hit since Sockets need to be created for each request but the app does not make a significant number of requests so this is acceptable.

这篇关于如何从HttpsURLConnection的prevent CONNECT方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆