Although the code is similar, but slightly changed some, hehe ... Thank you very much for the original owner.
Here is the code I changed. (hehe, although the change is not small)
private static string url = "Http://xxx/api/v1/video/Register";p ublic void Regist () {map<string, object> requestparamsmap = new hashmap<string, Object> (); requestparamsmap.put ("username", "test11"); requestparamsmap.put ("Password", "111"); printwriter printwriter = null; httpurlconnection conn = null; bufferedreader bufferedreader = null ; stringbuffer responseresult = new stringbuffer (); stringbuffer params = new stringbuffeR (); // organization request Parameters iterator it = requestparamsmap.entryset (). Iterator (); while (It.hasnext ()) { Map.Entry element = (map.entry) It.next (); params.append ( Element.getkey ()); Params.append ("="); Params.append (Element.getvalue ()); params.append ("&"); } if (Params.length () > 0) { params.deletecharat (Params.length () - 1); } try { string newurl = url + "?" + params; //First contact with this thing, directly stitching on the address Url url = new url (Newurl); conn = (HttpURLConnection) url.openconnection (); conn.setrequestmethod ("POST");// commit mode conn.setrequestproperty ("Content-type", "Plain/text; charset=utf-8"); // Set the common request properties &nbSp;conn.setrequestproperty ("Accept", "*/*"); conn.setrequestproperty ("Connection", "keep-alive"); // send a POST request must set the following two lines conn.setdooutput (True); conn.setdoinput (True); conn.connect (); int responsecode = conn.getresponsecode (); if (responsecode != 200) { system.out.println ( "Not success"); } else { system.out.println ("Success"); } // define the BufferedReader input stream to read the responsedata of the URL bufferedreader = new bufferedreader (new InputStreamReader ( conn.getinputstream ())); String line; while ((Line = bufferedreader.readline ()) != null ) { &nbsP; responseresult.append ("/n"). Append (line); } /* Displays response in Dialog */showdialog ("Registered success" + responseresult.tostring (). Trim ());/* Close dataoutputstream */} catch (ioexception e) {e.printstacktrace ();} catch (exception e) {e.printstacktrace ();} Finally{conn.disconnect (); try { if (printwriter != null) { printwriter.close (); } if (bufferedreader != null) { bufferedreader.close (); } } catch ( IOEXCEPTION&NBSP;EX) { ex.printstacktrace (); } }}
Originally do not want to directly splicing parameters in the address, but the use of OutputStream input stream is always reported 404, lazy directly spell on.
Hope to help others.
HttpURLConnection accessing WEBAPI Code