use of javax.net.ssl.HttpsURLConnection in project jfinal by jfinal.
the class HttpKit method getHttpConnection.
private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
URL _url = new URL(url);
HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
if (conn instanceof HttpsURLConnection) {
((HttpsURLConnection) conn).setSSLSocketFactory(sslSocketFactory);
((HttpsURLConnection) conn).setHostnameVerifier(trustAnyHostnameVerifier);
}
conn.setRequestMethod(method);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setConnectTimeout(19000);
conn.setReadTimeout(19000);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
if (headers != null && !headers.isEmpty())
for (Entry<String, String> entry : headers.entrySet()) conn.setRequestProperty(entry.getKey(), entry.getValue());
return conn;
}
use of javax.net.ssl.HttpsURLConnection in project Honu by jboulon.
the class THttpClient method flush.
public void flush() throws TTransportException {
// Extract request and reset buffer
byte[] data = requestBuffer_.toByteArray();
requestBuffer_.reset();
try {
// Create connection object
HttpURLConnection connection = (HttpURLConnection) url_.openConnection();
if (turnOffSSLHostnameVerifier && connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection).setHostnameVerifier(alwaysTrueHostnameVerifier);
}
// Timeouts, only if explicitly set
if (connectTimeout_ > 0) {
connection.setConnectTimeout(connectTimeout_);
}
if (readTimeout_ > 0) {
connection.setReadTimeout(readTimeout_);
}
// Make the request
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-thrift");
connection.setRequestProperty("Accept", "application/x-thrift");
connection.setRequestProperty("User-Agent", "Java/THttpClient");
if (customHeaders_ != null) {
for (Map.Entry<String, String> header : customHeaders_.entrySet()) {
connection.setRequestProperty(header.getKey(), header.getValue());
}
}
connection.setDoOutput(true);
connection.connect();
connection.getOutputStream().write(data);
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new TTransportException("HTTP Response code: " + responseCode);
}
// Read the responses
inputStream_ = connection.getInputStream();
} catch (IOException iox) {
throw new TTransportException(iox);
}
}
use of javax.net.ssl.HttpsURLConnection in project jersey by jersey.
the class SslHttpUrlConnectorTest method testSSLWithCustomSocketFactory.
/**
* Test to see that the correct Http status is returned.
*
* @throws Exception in case of a test failure.
*/
@Test
public void testSSLWithCustomSocketFactory() throws Exception {
final SSLContext sslContext = getSslContext();
final CustomSSLSocketFactory socketFactory = new CustomSSLSocketFactory(sslContext);
final ClientConfig cc = new ClientConfig().connectorProvider(new HttpUrlConnectorProvider().connectionFactory(new HttpUrlConnectorProvider.ConnectionFactory() {
@Override
public HttpURLConnection getConnection(final URL url) throws IOException {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(socketFactory);
return connection;
}
}));
final Client client = ClientBuilder.newBuilder().withConfig(cc).sslContext(sslContext).register(HttpAuthenticationFeature.basic("user", "password")).register(LoggingFeature.class).build();
final Response response = client.target(Server.BASE_URI).path("/").request().get();
assertEquals(200, response.getStatus());
assertTrue(socketFactory.isVisited());
}
use of javax.net.ssl.HttpsURLConnection in project Smack by igniterealtime.
the class AbstractSmackIntTest method getHttpUrlConnectionFor.
protected HttpURLConnection getHttpUrlConnectionFor(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
if (sinttestConfiguration.tlsContext != null && urlConnection instanceof HttpsURLConnection) {
HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) urlConnection;
httpsUrlConnection.setSSLSocketFactory(sinttestConfiguration.tlsContext.getSocketFactory());
}
return urlConnection;
}
use of javax.net.ssl.HttpsURLConnection in project Talon-for-Twitter by klinker24.
the class FavoriterUtils method getJson.
public JSONObject getJson(long tweetId) {
try {
String url = "https://twitter.com/i/activity/favorited_popup?id=" + tweetId;
URL obj = new URL(url);
HttpsURLConnection connection = (HttpsURLConnection) obj.openConnection();
connection.setRequestProperty("Content-Type", "text/html");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestMethod("GET");
connection.setRequestProperty("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
String docHtml = sb.toString();
try {
connection.disconnect();
} catch (Exception e) {
}
return new JSONObject(docHtml);
} catch (Exception e) {
return null;
}
}
Aggregations