我的問題是如果我輸入用戶名,密碼,電子郵件註冊失敗的吐司消息出現。任何一個在背景任務類和主要活動中解決這個問題?Webservice中的問題
請問任何人都可以進入它看起來像註冊成功?
public void submitDetails(View v)
{
String username = et.getText().toString();
String password = et1.getText().toString();
String email = et2.getText().toString();
String emailpatern = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
if (username.equals("")) {
et.setError("pls enter name");
} else if (password.equals("")) {
et1.setError("pls enter last name");
} else if (email.equals("")) {
et2.setError("Pls Enter Valid Email");
} else if (!email.matches(emailpatern)) {
et2.setError("Pls Enter Valid email charcters");
}
BackgroundTask backgroundTask = new BackgroundTask();
backgroundTask.execute(username,password,email);
}
class BackgroundTask extends AsyncTask<String,Void,String>
{
String reg_url;
@Override
protected void onPreExecute() {
reg_url ="http://iwt.devxenorix.com/webservices/create-user.php";
}
@Override
protected String doInBackground(String... args)
{
String username,password,email;
username = args[0];
password = args[1];
email = args[2];
try {
URL ur = new URL(reg_url);
HttpURLConnection httpURLConnection = (HttpURLConnection) ur.openConnection();
OutputStream outputStream = httpURLConnection.getOutputStream();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String register = URLEncoder.encode("username","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&"+
URLEncoder.encode("password","UTF-8")+"="+URLEncoder.encode(password,"UTF-8")+"&"+
URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8");
bufferedWriter.write(register);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
inputStream.close();
httpURLConnection.disconnect();
return "Registered...";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "register failure";
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
}
}
}
請檢查您的反應是正確的或者也不在郵遞員或hurlit。 – Lampard