Post request client side code:
1.
public void String Loginbypost (string username,string pwd) {
String path = "";
URL url = new URL (paht);
HttpURLConnection conn = (httpurlconnection) url.openconnection ();
Conn.setconnecttimeout (5000);//Request timed out
Conn.setrequestmehtod ("POST");
Preparing data
String data = "Username=" + username + "&pwd=" + pwd;
Conn.setrequestproperty ("Content-type", "application/x-form-urlencoded");
Conn.setrequestproperty ("Content-length", Data.length + "");
Conn.setdooutput (TRUE); Whether to allow data to be written out
Oputstream OS = Conn.getoutputstream ();
Os.write (Data.getbyte ());
int code = Conn.getresponsecode ();
if (code = = 200) {
InputStream is = Conn.getinputstream ();
String Text = Streamtool.readinputstream (IS);
return text;
}else{
return null;
}
}
2.
public void string Loginclientpost (string username, string pwd) {
HttpClient client = new Defulthttpclient ();
String path = "";
HttpPost = post = new HttpPost (path);
list<namevaluepair> Paimer = new arraylist<namevaluepair> ();
Paimer.add (New Basicnamevaluepair ("username", username));
Post.setentity (New Urlencodedformentiry (Paimer, "UTF-8"));
HttpResponse response = Client.excute (POST);
int code = Response.getstatusline (). Getstatuscode ();
if (code = = 200) {
InputStream is = Response.getentity (). getcontent ();
String Text = Streamtool.readstream (IS);
return text;
}else{
return null;
}
}
Post transfer of client-side interaction with server-side JSON data: