Web or corporate intranet server image display to page via HTTP request

Source: Internet
Author: User

<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>   &nbsp    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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.