本文整理了Java中javax.net.ssl.HttpsURLConnection.connect()
方法的一些代码示例,展示了HttpsURLConnection.connect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.connect()
方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:connect
暂无
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader indata = new BufferedReader(new InputStreamReader(is));
代码示例来源:origin: Javen205/IJPay
conn.connect();
代码示例来源:origin: Javen205/IJPay
conn.connect();
代码示例来源:origin: wildfly/wildfly
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.connect();
InputStream inputStream = conn.getInputStream();
response = Json.createReader(inputStream).readObject();
代码示例来源:origin: youseries/ureport
@Override
public InputStream getImage(String path) {
try{
URL url=new URL(path);
HttpsURLConnection connection=(HttpsURLConnection)url.openConnection();
connection.connect();
InputStream inputStream=connection.getInputStream();
return inputStream;
}catch(Exception ex){
throw new ReportException(ex);
}
}
代码示例来源:origin: com.bstek.ureport/ureport2-core
@Override
public InputStream getImage(String path) {
try{
URL url=new URL(path);
HttpsURLConnection connection=(HttpsURLConnection)url.openConnection();
connection.connect();
InputStream inputStream=connection.getInputStream();
return inputStream;
}catch(Exception ex){
throw new ReportException(ex);
}
}
代码示例来源:origin: com.microsoft.azure.iothub-java-client/iothub-java-device-client
/**
* Sends the request to the URL given in the constructor.
*
* @throws IOException if the connection could not be established, or the
* server responded with a bad status code.
*/
public void connect() throws IOException
{
// Codes_SRS_HTTPSCONNECTION_11_004: [The function shall stream the request body, if present, through the connection.]
if (this.body.length > 0)
{
this.connection.setDoOutput(true);
this.connection.getOutputStream().write(this.body);
}
// Codes_SRS_HTTPSCONNECTION_11_003: [The function shall send a request to the URL given in the constructor.]
// Codes_SRS_HTTPSCONNECTION_11_005: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
this.connection.connect();
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Sends the request to the URL given in the constructor.
*
* @throws IOException This exception thrown if the connection could not be established,
* or the server responded with a bad status code.
*/
public void connect() throws IOException
{
// Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_006: [The function shall stream the request body, if present, through the connection.]
if (this.body.length > 0)
{
this.connection.setDoOutput(true);
this.connection.getOutputStream().write(this.body);
}
// Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_005: [The function shall send a request to the URL given in the constructor.]
// Codes_SRS_SERVICE_SDK_JAVA_HTTPCONNECTION_12_007: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
this.connection.connect();
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Sends the request to the URL given in the constructor.
*
* @throws IOException This exception thrown if the connection could not be established,
* or the server responded with a bad status code.
*/
public void connect() throws IOException
{
// Codes_SRS_HTTPCONNECTION_25_006: [The function shall stream the request body, if present, through the connection.]
if (this.body.length > 0)
{
this.connection.setDoOutput(true);
this.connection.getOutputStream().write(this.body);
}
// Codes_SRS_HTTPCONNECTION_25_005: [The function shall send a request to the URL given in the constructor.]
// Codes_SRS_HTTPCONNECTION_25_007: [The function shall throw an IOException if the connection could not be established, or the server responded with a bad status code.]
this.connection.connect();
}
代码示例来源:origin: gradle.plugin.com.rosberry.android.gradle/rawf
private String sendGet(String urlAddress) throws Exception {
HttpsURLConnection connection = null;
try {
System.out.println("Request url: " + urlAddress);
URL url = new URL(urlAddress);
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
initConnection(connection);
addHeaders(connection);
connection.connect();
System.out.println("Response code: " + connection.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
return br.readLine();
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
代码示例来源:origin: vmware/admiral
private static void handleCertForHttpsThroughHttpProxyWithAuth(URL url, Proxy proxy,
String proxyUsername, String proxyPassword, long timeout,
SSLSocketFactory socketFactory) throws IOException {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(proxy);
connection.setSSLSocketFactory(socketFactory);
connection.setConnectTimeout((int) (timeout < 0 ? 0 : timeout));
if (proxyUsername != null && proxyPassword != null) {
byte[] token = (proxyUsername + ":" + proxyPassword)
.getBytes(StandardCharsets.UTF_8);
connection.setRequestProperty(REQUEST_HEADER_PROXY_AUTHORIZATION,
"Basic " + Base64.encodeBase64StringUnChunked(token));
}
connection.connect();
connection.disconnect();
}
代码示例来源:origin: ge0rg/MemorizingTrustManager
public void run() {
try {
URL u = new URL(urlString);
HttpsURLConnection c = (HttpsURLConnection)u.openConnection();
c.connect();
setText("" + c.getResponseCode() + " "
+ c.getResponseMessage(), false);
c.disconnect();
} catch (Exception e) {
setText(e.toString(), false);
e.printStackTrace();
}
}
}.start();
代码示例来源:origin: com.vmware/vijava
private static HttpsURLConnection getHTTPConnection(String urlStr, String cookieStr) throws IOException
{
HostnameVerifier hv = new HostnameVerifier()
{
public boolean verify(String urlHostName, SSLSession session)
{
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setAllowUserInteraction(true);
conn.setRequestProperty("Cookie", cookieStr);
conn.connect();
return conn;
}
代码示例来源:origin: com.hazelcast/hazelcast-all
private Map<Address, Address> callService() throws IOException, CertificateException {
URL url = new URL(endpointUrl);
HttpsURLConnection httpsConnection = (HttpsURLConnection) url.openConnection();
httpsConnection.setRequestMethod("GET");
httpsConnection.setConnectTimeout(connectionTimeoutInMillis);
httpsConnection.setReadTimeout(connectionTimeoutInMillis);
httpsConnection.setRequestProperty("Accept-Charset", "UTF-8");
httpsConnection.connect();
checkCertificate(httpsConnection);
checkError(httpsConnection);
return parseResponse(httpsConnection.getInputStream());
}
代码示例来源:origin: io.takari/jdkget
public static JdkReleases readFromGithub() throws IOException {
HttpsURLConnection conn = (HttpsURLConnection) new URL(REMOTE_XML).openConnection();
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setUseCaches(true);
conn.setRequestMethod("GET");
conn.setConnectTimeout(TIMEOUT_VALUE);
conn.setReadTimeout(TIMEOUT_VALUE);
conn.connect();
return read(conn.getInputStream());
}
代码示例来源:origin: guardianproject/NetCipher
@Test
public void testCannotConnectHttps() throws MalformedURLException, KeyManagementException {
// TODO test connecting to http://
// TODO test connecting to non-HTTPS port
try {
HttpsURLConnection https = NetCipher.getHttpsURLConnection(new URL(
"https://127.0.0.1:63453"));
https.setConnectTimeout(0); // blocking connect with TCP timeout
https.connect();
fail();
} catch (IOException e) {
// this should not connect
}
}
代码示例来源:origin: line/line-sdk-android
@Test
public void testNetworkErrorByGet() throws Exception {
IOException ioException = new IOException();
doThrow(ioException).when(httpsURLConnection).connect();
LineApiResponse<String> responseData = target.get(
Uri.parse("https://test"),
Collections.<String, String>emptyMap() /* requestHeaders */,
Collections.<String, String>emptyMap() /* queryParameters */,
new StringResponseParser());
assertFalse(responseData.isSuccess());
assertEquals(LineApiResponseCode.NETWORK_ERROR, responseData.getResponseCode());
assertEquals(new LineApiError(ioException), responseData.getErrorData());
}
代码示例来源:origin: line/line-sdk-android
@Test
public void testNetworkErrorByPost() throws Exception {
IOException ioException = new IOException();
doThrow(ioException).when(httpsURLConnection).connect();
LineApiResponse<String> responseData = target.post(
Uri.parse("https://test"),
Collections.<String, String>emptyMap() /* requestHeaders */,
Collections.<String, String>emptyMap() /* postData */,
new StringResponseParser());
assertFalse(responseData.isSuccess());
assertEquals(LineApiResponseCode.NETWORK_ERROR, responseData.getResponseCode());
assertEquals(new LineApiError(ioException), responseData.getErrorData());
}
代码示例来源:origin: line/line-sdk-android
@Test
public void testNetworkErrorByDelete() throws Exception {
IOException ioException = new IOException();
doThrow(ioException).when(httpsURLConnection).connect();
LineApiResponse<String> responseData = target.delete(
Uri.parse("https://test"),
Collections.<String, String>emptyMap() /* requestHeaders */,
new StringResponseParser());
assertFalse(responseData.isSuccess());
assertEquals(LineApiResponseCode.NETWORK_ERROR, responseData.getResponseCode());
assertEquals(new LineApiError(ioException), responseData.getErrorData());
}
代码示例来源:origin: line/line-sdk-android
@Test
public void testNetworkErrorByPostWithJson() throws Exception {
IOException ioException = new IOException();
doThrow(ioException).when(httpsURLConnection).connect();
LineApiResponse<String> responseData = target.postWithJson(
Uri.parse("https://test"),
Collections.<String, String>emptyMap() /* requestHeaders */,
"" /* postData */,
new StringResponseParser());
assertFalse(responseData.isSuccess());
assertEquals(LineApiResponseCode.NETWORK_ERROR, responseData.getResponseCode());
assertEquals(new LineApiError(ioException), responseData.getErrorData());
}
内容来源于网络,如有侵权,请联系作者删除!