<span style= "White-space:pre" ></span>/** * @author luoguohui * @date July 16, 2015 * Description: Obtain online or corporate intranet server images via HTTP request * @params urlstr such as HT tp://creatim.allyes.com.cn/imedia/csdn/20150715/15_39_00_5a1e2c1e.jpg * @return Base64String */ public string Getimagebase64onservice (string urlstr) { <span style= " White-space:pre "></span>inputstream bis = null; httpurlconnection httpurl = null; URL url = null; try { <span style= "White-space:pre" ></span> &NBS p;url = new URL (<span style= "font-family:arial, Helvetica, Sans-serif;" >urlstr</span><span style= "font-family:arial, Helvetica, Sans-serif;" >); </span><span style= "White-space:pre" ></span> &nBsp httpurl = (httpurlconnection) url.openconnection (); <span style= "White-space:pre" ></span> httpurl.connect (); <span style= "White-space:pre" ></span> bis = Httpurl.getinputstream (); <span style= "White-space:pre" ></span> bytearrayoutputstream output = new Bytearrayoutputstream (); <span style= "White-space:pre" ></span> byte[] buffer = New Byte[4096];<span style= "White-space:pre" ></span> int n = 0;<span style= " White-space:pre "></span> while ( -1! = (n = bis.read (buffer))) {<span style=" white- Space:pre "></span> output.write (buffer, 0, N); <span style=" White-space:pre "></span> }<span style=" White-space:pre "></span>   output.tobytearray () <span style= "White-space:pre" ></span> String imageBase64 = base64.bytearraytobase64 (Output.tobytearray ()); <span style= "White-space:pre" >< /SPAN> return imagebase64; } catch (IOException e) { } catch (ClassCastException e) { } finally { <span style= "White-space:pre" ></span> try { <span style= "White-space:pre" > </span> bis.close (); <span style= "White-space:pre" ></span> httpurl.disconnect (); <span style= "White-space:pre" ></span> } catch (IOException e) { < Span style= "White-space:pre" ></span> } catch (NullPointerException e) { < Span Style= "WHite-space:pre "></span> } } &nbs P Return null; }
The following is how the front page is displayed
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Web or corporate intranet server image display to page via HTTP request