我有一个使用第三方服务器的应用。服务器支持https / http请求。
对于我的应用,我创建了一个自签名证书,以便与服务器建立https连接。但是,我经常得到"请求超时"与
"SSL handshake timeout"
占主导地位。
但是,我切换到HTTP连接,然后大大减少了超时。
有没有人遇到过同样的问题?
如果在Android的PROD / Release环境中HTTPS超时,是否可以回退到HTTP连接?
进行连接的代码
String http_scheme = "http";
int http_port = 80;
String https_scheme = "https";
int https_port = 443;
ProtocolSocketFactory customFactory = new EasySslProtocolSocketFactory();
Protocol lEasyHttps = new Protocol(https_scheme, customFactory, https_port);
Protocol.registerProtocol(https_scheme, lEasyHttps);
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(host, http_port, http_scheme);
HttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
int connectTimeout = 30*1000;
params.setConnectionTimeout(connectTimeout);
params.setSoTimeout(connectTimeout);
connectionManager.setParams(params);