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