当前位置: 首页>>代码示例>>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;未经允许,请勿转载。