本文整理汇总了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()));
}
示例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;
}