62,625
社区成员
发帖
与我相关
我的任务
分享public HttpURLConnection connect(String url, String method) throws MalformedURLException, IOException {
SocketAddress addr = new InetSocketAddress("",8048);
Proxy typeProxy = new Proxy(Proxy.Type.HTTP,addr);
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(typeProxy);
connection.setConnectTimeout(600);
// HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
if (sslSocketFactory != null) {
HttpsURLConnection httpsConn = (HttpsURLConnection) connection;
httpsConn.setSSLSocketFactory(sslSocketFactory);
if (sslConfig.ignoreHostname) {
httpsConn.setHostnameVerifier(ignoreHostnameVerifier);
}
}
connection.setConnectTimeout(config.connectTimeout);
connection.setReadTimeout(config.readTimeout);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod(method);
connection.setRequestProperty("User-Agent", httpConfig.userAgent);
connection.setRequestProperty("Connection", httpConfig.connection);
connection.setRequestProperty("Content-Type", httpConfig.contentType + ";charset=" + config.charset);
connection.setRequestProperty("Accept", httpConfig.accept);
connection.setRequestProperty("Accept-Charset", config.charset);
// NOT connect, delay until send() for set length
return connection;
}