Final String urlPath = "http: // 60.123.36.163: 8080/wms/resisteruser. do ";
URL url;
Try
{
Url = new URL (urlPath );
/* Encapsulate sub-objects */
JSONObject ClientKey = new JSONObject ();
ClientKey. put ("appusername", userName. getText (). toString ());
ClientKey. put ("eigenvalues", passWord. getText (). toString ());
ClientKey. put ("telephone", phoneNum. getText (). toString ());
ClientKey. put ("apprealname", realName. getText (). toString ());
ClientKey. put ("email", emailNum. getText (). toString ());
ClientKey. put ("sex", sex );
/* Encapsulate the Person array */
JSONObject params = new JSONObject ();
Params. put ("Person", ClientKey );
/* Convert JSON data to String type and use the output to the server to write */
String content = String. valueOf (params );
HttpURLConnection conn = (HttpURLConnection) url. openConnection ();
Conn. setConnectTimeout (5000 );
Conn. setDoOutput (true); // you can specify whether the output is allowed.
Conn. setRequestMethod ("POST ");
Conn. setRequestProperty ("User-Agent", "Fiddler ");
Conn. setRequestProperty ("Content-Type", "application/json ");
OutputStream OS = conn. getOutputStream ();
OS. write (content. getBytes ());
OS. close ();
/* Response code returned by the server */
Int code = conn. getResponseCode ();
If (code = 1)
{
Toast. makeText (Register. this, "Congratulations! ", Toast. LENGTH_SHORT). show ();
Intent intentToLogin = new Intent ();
IntentToLogin. setClass (Register. this, Login. class );
StartActivity (intentToLogin );
}
}
Catch (Exception e)
{
E. printStackTrace ();
}