Page 121 - MDP2022-2
P. 121
@Override
public void onClick(View view) {
Intent intent = new Intent(SubActivity.this ,MainActivity.class);
String data_id = register_id.getText().toString();
String data_pw = register_pw.getText().toString();
String data_name = register_name.getText().toString();
String data_phone = register_phone.getText().toString();
SubActivity.GetData task = new SubActivity.GetData();
task.execute(data_id, data_pw, data_name, data_phone);
}
});
}
private class GetData extends AsyncTask<String, Void, String> {
ProgressDialog progressDialog;
String errorString = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(SubActivity.this,"잠시만 기다려 주세요", null, tru
e, true);
}
@Override
protected String doInBackground(String... params) {
String serverURL = "http://192.168.0.25:8181/android/register.php";
String postParameters = "id=" + params[0] + "&pwd=" + params[1] + "&name=" +
params[2] + "&number=" + params[3];
try {
URL url = new URL(serverURL);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnectio
n();
httpURLConnection.setReadTimeout(5000);
httpURLConnection.setConnectTimeout(5000);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
OutputStream outputStream = httpURLConnection.getOutputStream();
outputStream.write(postParameters.getBytes("UTF-8"));
outputStream.flush();
outputStream.close();
int responseStatusCode = httpURLConnection.getResponseCode();