我在我的Android應用程序中忘記了密碼頁面。如果我沒有輸入任何電子郵件,它會從服務器返回正確的響應,如果我輸入了在我們的數據庫中找到的電子郵件,那麼它會向用戶發送一封電子郵件並從服務器返回正確的響應。但是,如果我在一封電子郵件中輸入,它是不是在我們的數據庫中發現,當我打電話HTTPEntity給出空值
HttpEntity entity = response.getEntity();
實體爲空值。我不確定爲什麼它可以用於2個案例,但不是第三個。
有誰知道這是爲什麼?我的代碼如下
的Android代碼:
private void accessURL(String url) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
if (url.equalsIgnoreCase(Global.forgotPasswordURL)) {
InputStream is = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", email.getText().toString()));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if(entity != null){
is = entity.getContent();
String jsonResult = inputStreamToString(is).toString();
if (jsonResult.equalsIgnoreCase("Please enter your Email")) {
new AlertDialog.Builder(this).setTitle("Please Enter Your Email Address")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
}).show();
}else if(jsonResult.equalsIgnoreCase("Email Address Not Found")){
new AlertDialog.Builder(this).setTitle("The Email Address You Entered has not Been Found").setMessage("Make sure that you entered your email correctly.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}else{
new AlertDialog.Builder(this).setTitle("Your Email Has Been Found!").setMessage("Check the email you provied for further instructions on resetting your password.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
}else{
Log.d("Null", "null");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
PHP代碼:
if (isset($_POST["email"]) && !empty($_POST['email'])) {
$con=mysqli_connect("localhost","***********","******","*******");
$email = $_POST['email'];
$query = mysql_query("SELECT * FROM users WHERE email = '$email'");
$query2 = mysql_query("SELECT * FROM tempusers WHERE email = '$email'");
$ans = mysql_num_rows($query);
$ans2 = mysql_num_rows($query2);
$str = $ans . " " . $ans2;
if(mysql_num_rows($query) == 0 && mysql_num_rows($query2) == 0){
sendResponse(205, "Email Address Not Found");
return false;
}
$temp = false;
if(mysql_num_rows($query2) != 0){
$temp = true;
$query1 = mysql_query("SELECT * FROM tempusers WHERE email = '$email'");
$row = mysql_fetch_array($query1);
mailUser($email, $row['firstname'], $temp);
sendResponse(200, "Email Address Found".$str);
return true;
}else{
$query1 = mysql_query("SELECT * FROM users WHERE email = '$email'");
$row = mysql_fetch_array($query1);
mailUser($email, $row['firstname'], $temp);
sendResponse(200, "Email Address Found".$str);
return true;
}
}
sendResponse(400, 'Please enter your Email');
return false;
任何解決這個幫助將不勝感激,謝謝!
謝謝,這工作!我使狀態碼與其他狀態碼不同的唯一原因是因爲在iPhone版本的應用程序中,我需要第三個狀態碼來區分這三種不同的情況,所以我只是選擇了另一個代碼。 – shadowarcher