當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpsURLConnection.getHeaderField方法代碼示例

本文整理匯總了Java中javax.net.ssl.HttpsURLConnection.getHeaderField方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpsURLConnection.getHeaderField方法的具體用法?Java HttpsURLConnection.getHeaderField怎麽用?Java HttpsURLConnection.getHeaderField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.HttpsURLConnection的用法示例。


在下文中一共展示了HttpsURLConnection.getHeaderField方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHttpsCookie

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
@Test
public void testHttpsCookie() throws IOException, GeneralSecurityException {
  URL base = new URL("https://" + NetUtils.getHostPortString(server
          .getConnectorAddress(1)));
  HttpsURLConnection conn = (HttpsURLConnection) new URL(base,
          "/echo").openConnection();
  conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());

  String header = conn.getHeaderField("Set-Cookie");
  List<HttpCookie> cookies = HttpCookie.parse(header);
  Assert.assertTrue(!cookies.isEmpty());
  Assert.assertTrue(header.contains("; HttpOnly"));
  Assert.assertTrue(cookies.get(0).getSecure());
  Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:TestHttpCookieFlag.java

示例2: download

import javax.net.ssl.HttpsURLConnection; //導入方法依賴的package包/類
public static String download(String media_id) {
	try {
		String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token="
				+ WeiXinCompanyUtils.getToken() + "&media_id=" + media_id;

		URL url = new URL(urlStr);
		HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
		conn.setDoInput(true);

		String disposition = conn.getHeaderField("Content-disposition");
		if (disposition == null) {
			return null;
		}

		String[] s = disposition.split(";");

		String ss[] = s[1].trim().split("\\=");
		String fileName = ss[1].trim().replaceAll("\"", "");
		// fileName.getBytes("iso-8859-1");
		fileName = new String(fileName.getBytes("iso-8859-1"), "utf-8");

		String path = "/www/gd_image/" + fileName;
		File file = new File(path);
		if (!file.exists()) {
			file.createNewFile();
		}
		FileOutputStream fos = new FileOutputStream(file);
		InputStream input = conn.getInputStream();
		byte[] bytes = new byte[2048];
		int size = 0;
		while ((size = input.read(bytes)) != -1) {
			fos.write(bytes, 0, size);
		}
		input.close();
		fos.close();
		return fileName;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:42,代碼來源:WeiXinCompanyDownload.java


注:本文中的javax.net.ssl.HttpsURLConnection.getHeaderField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。