Send a picture to the server using post

Source: Internet
Author: User

Local photo, send to Server "POST"

Sent in binary byte[] mode

A picture of about 300K, one send completed

Post request @suppresslint ("Handlerleak") public static boolean postrequest (String urlpath,  BYTE[] B) {Try{url url=new url (URLPath);  httpurlconnection con= ( httpurlconnection) url.openconnection ();   con.setrequestmethod ("POST");   con.setreadtimeout (5*1000); Con.setdooutput (true);//Open Outward output    con.setrequestproperty ("Content-type",  http. UTF_8);//Content Type    con.setrequestproperty ("Content-length", String.valueof (B.length));//Length     outputstream outstream=con.getoutputstream ();   outstream.write (b);//Write Data     outstream.flush ();//Flush Memory    outstream.close ();//Status code is unsuccessful if (Con.getresponsecode () ==200 {  LOG.E ("result", "transfer succeeded"), RETURN TRUE;  } ELSE{LOG.V ("result",  "code  =  " + con.getresponsecode ());}} catch (exception e) {e.printstacktrace ();} return false;   }
Time consuming operation, opening a thread private Runnable mrunnable = new Runnable () {public void run () {String IP = "Http://192.168.1.100/ZD_BaseData Trans_sql/uploadpicture.aspx ";//httpclientpost (imgToBase64 (camerapath, NULL, NULL), IP);p ostrequest (IP, Getimgstring (Camerapath, NULL, NULL)); Mhandler2.sendmessage (Mhandler.obtainmessage ());}};

Camerapath The local path saved for the photo

This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1622335

Send a picture to the server using post

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.