The simple difference between the request mode get and post:
The Get method is to append parameters to the URL address, such as the following:
http://localhost:8080/loginServlet.html?username=123&password=456
Post is to put the request parameters into the request body, stream to the server, in addition to upload files, must be the post mode
The following code simulates a user login by using the Post method
Com.yuanlp.qqloginpostandroid.os.Bundleandroid.support.v7.app.AppCompatActivityandroid.text.TextUtilsandroid.view.Viewand Roid.widget.Buttonandroid.widget.CheckBoxandroid.widget.EditTextandroid.widget.Toastorg.json.JSONExceptionorg.json.JSONOb Jectjava.io.BufferedReaderjava.io.InputStreamjava.io.InputStreamReaderjava.net.HttpURLConnectionjava.net.URLjava.net.URLE Ncodermainactivity appcompatactivity { ==edittext edittext checkbox Button String String (bundle savedinstancestate) { .oncreate (savedinstancestate) Setcontentview (r.layout.) = (EditText) findviewbyid (r.id.) = (EditText) findviewbyid (r.id.) = (CheckBox) findviewbyid (r.id.) = (Button) findviewbyid (r.id.)} (View view) { = .gettext (). ToString (). Trim () = .gettext (). ToString (). Trim () (Textutils. (). TexTutils. ()) { toast. (Toast.). Show ()} .setenabled () Thread () { () { { thread. () String path=url url = url (path) httpurlconnection conn = ( httpurlconnection) url.openconnection () Conn.setrequestmethod () Conn.setconnecttimeout () Conn.setrequestproperty () String data=+ urlencoder. () ++urlencoder. () Conn.setrequestproperty (String. ( Data.length ())) Conn.setdooutput () Conn.getoutputstream (). Write (Data.getbytes ()) code = Conn.getresponsecode () (code==) { &nbsP; inputstream is=conn.getinputstream () BufferedReader br= BufferedReader (InputStreamReader (IS)) Stringbuffer sb=stringbuffer () string len= ((Len=br.readLine ())! = ) { sb.append (len)} string result=sb.tostring () runtoastanythread (Result)} } (exception e) { E.printstacktrace ()} } }.starT ()} (String result) { Runonuithread (Runnable () { () { JSONObject jsonobject={ jsonobject=jsonobject () String code=jsonobject.get (). ToString () (. Equals (code)) { toast. (Getapplicationcontext () Toast.). Show ()} (. Equals (code)) { toast. (Getapplicationcontext () Toast.). Show ()} } (JSOnexception e) { e.printstacktrace ()} } })}}
This article is from the "Yuangushi" blog, make sure to keep this source http://cm0425.blog.51cto.com/10819451/1941138
Android Post way to send data to background server