how to download file over ssl (https) on android -
i have app working using code below http, security reasons being changed https, causes download fail. tried changing httpurlconnection
httpsurlconnection
did not work.
try { fileoutputstream f = new fileoutputstream(directory); url u = new url(fileurl); httpurlconnection c = (httpurlconnection) u.openconnection(); c.setrequestmethod("get"); c.setdooutput(true); c.connect(); inputstream in = c.getinputstream(); byte[] buffer = new byte[1024]; int len1 = 0 while ((len1 = in.read(buffer)) > 0) { f.write(buffer, 0, len1); log.d("downloader","downloading"); } f.close(); } catch (exception e) { e.printstacktrace(); log.d("downloader", "catch"); }
there no particular passwords or needed connect computer , in fact if go browser on android phone , type in https url in question loads fine... cant figure out how in app.
i have virtually no experience security or certificates or of not sure needed here or look.
thanks
have @ https , ssl article within android documentation. have simple example in there, given https certificate signed trusted ca (as write you're able use server browser have such signed certificate):
url url = new url("https://wikipedia.org"); urlconnection urlconnection = url.openconnection(); inputstream in = urlconnection.getinputstream(); copyinputstreamtooutputstream(in, system.out);
Comments
Post a Comment