The example of this article tells the way Java realizes the method and text of the Sina Weibo OAUTH interface. Share it for everyone for your reference. The specifics are as follows:
Based on many people on the Internet using Sina API to develop the Sina Weibo client, many people have stuck in this cloth. Now present the code, hoping to help some friends.
/*** Posted a picture of the picture with pictures* @param token* @param tokensecret* @param Afile* @Param Status* @Param Urlpath* @Return*/Public String uploadStatus (String To Ken, String Tokensecret, File Afile, String Status , String urlpath) {httpoauthconsumer = new defaultoAuthConsumer (consumerkey, consumersecret); RET); String Result = NULL; TRY {url url = new url (urlpath); httpurlConnection request = (httpurlConnection) URL.opennection ( ); Request.Setdooutput (TRUE); Request.SetRequestMethod ("Post"); httpparameters Para = New Httpparameters (); Para.put ("STATUS", de (STATUS, "UTF-8"). REPLACEALL (" //+", "%20")); String boundary = "---------------------------37531613912423"; String content = " -"+Boundary+"/R/NCONTENT-DISPOSITION: Form-Data; name =/"status/"/r/n/r/n "; string pic ="/r/n- "+breakary+"/r. /nContent-Disposition: Form-Data; name =/"pic/"; Filename =/"Image.jpg/"/R/NContent-Type: Image/JPEG/R/N/R/N "; byte [] END_DATA = ("/r/n-" " + boundary +"-/r/n "). Getbytes (); ()]; stream.read (file); Request.SetRequestproperty ("Content-Type", "Multipart/Form-Data; Boundary ="+Boundary); Stproperty ("Content- LENGTH ", String.Valueof (Content.getBytes (). LENGTH + Status.Getbytes (). Length + pic.getBytes (). Set the content length httpoauthconsumer. SetAdDitionalParameters (Para); httpoauthconsumer.signer.sign (request); outputStream OT = Request.GetoutPutstream (); OT.Write (content.getbytes ()); o t.Write (Status.getbytes ()); OT.Write (pic.getbytes ()); OT.Write (File); OT.Write (END_DATA); OT.Flush (); OT.Close (); Request.connect (); if (200 == RequestResponsecode ()) {result = "Success";}} Catch (FilenotFoundexception E1) {e1.printstacktrace ();} Catch (IOEXCETION E) {e.printstacktrace ();} Catch ignexception E) {e.printstacktrace ();} Catch {e.printstacktrace ();} Catch (OauthCommunicationException E) {e.printstacktrace ();} Return Result;}It is hoped that this article is helpful to everyone's Java program design.