本文整理匯總了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;
}