Code example for HttpsURLConnection

Methods: connect, disconnect, setDoOutput, setRequestMethod

0
		InputStream is = null;
		try { 
			trustEveryone(); 
			url = new URL(MEKONG_URL + imageURL);
			hc = (HttpsURLConnection) url.openConnection();
			hc.setRequestMethod("GET");
			hc.setDoOutput(true);
			hc.connect();
 
			File dir = new File(whereToSave);
			if (!dir.exists()) {
				dir.mkdirs();
			} 
			File f = new File(dir, fileName);
			fos = new FileOutputStream(f);
 
			is = fetch(MEKONG_URL + imageURL);
 
			Bitmap bm = BitmapFactory.decodeStream(is);
			bm.compress(CompressFormat.PNG, 100, fos);
			fos.flush();
			bm = BitmapFactory.decodeFile(f.getAbsolutePath());
			return true; 
		} catch (MalformedURLException e) {
			e.printStackTrace();
			return false; 
		} catch (Exception e) {
			e.printStackTrace();
			return false; 
		} finally { 
			if (fos != null) {
				try { 
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				} 
			} 
			if (hc != null) {
				hc.disconnect();
			} 
			if (is != null) {
				try { 
					is.close();
				} catch (IOException e) {