2014-01-15 3 views
0

내 Android 앱에 비밀번호 분실 페이지가 있습니다. 이메일을 입력하지 않으면 서버에서 올바른 응답을 반환하고 데이터베이스에있는 이메일을 입력하면 사용자에게 이메일을 보내고 서버에서 올바른 응답을 반환합니다. 그러나 이메일에 입력 한 내용이 데이터베이스에없는 경우 전화 할 때HTTPEntity null 값 제공

HttpEntity entity = response.getEntity(); 

엔티티는 null 값입니다. 2 가지 경우에는 효과가 있지만 3 가지에는 효과가없는 이유는 확실하지 않습니다.

누구나 그 이유를 알고 있습니까?

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; 

이 어떤 도움이 고정이 크게 감사하겠습니다, 감사

안드로이드 코드를 다음과 같이 내 코드입니다!

답변

1

내가 이해하는 한, 205 응답의 경우 HttpEntity의 사양에 따라 동작합니다. 사양은 다음과 같습니다.

HTTP 메시지는 요청 또는 응답과 관련된 콘텐츠 엔터티를 전달할 수 있습니다. 엔티티는 일부 요청 및 일부 응답에서 찾을 수 있습니다. 엔티티를 사용하는 요청은 엔티티 엔 클로징 요청이라고하는 입니다. HTTP 사양 은 두 개의 엔티티 엔클로저 요청 메소드 인 POST와 PUT을 정의합니다. 응답 은 일반적으로 콘텐츠 엔터티를 묶어야합니다. HEAD 방법 및 204 콘텐츠 없음, 304 수정되지 않음, 205 Reset Content 응답에 대한이 규칙에 대한 예외 규칙은 입니다. 이메일은 PHP에서 404 응답 코드를 전송하고 자바 코드에서 확인할 수없는 경우

경우

:

if(response.getStatusLine().getStatusCode() == 404){ 
    //email was not found 
} 
+0

감사합니다. 다른 사람과 다른 상태 코드가있는 유일한 이유는 응용 프로그램의 iPhone 버전에서 세 가지 다른 경우를 구별하기 위해 세 번째 상태 코드가 필요했기 때문에 다른 코드를 선택했기 때문입니다. – shadowarcher

1

은 이메일 같은 200 코드를 전송

sendResponse(200, "Email Address Not Found"); 
뿐만 아니라 찾을 수 없습니다