2013-07-19 2 views
0

내가 URL 값 사용자 이름과 암호로그인 인증은

그리고 자바 코드,

public class AndroidHTTPRequestsActivity extends Activity implements OnClickListener { 

    private EditText usernameEditText; 
    private EditText passwordEditText; 
    private Button sendGetReqButton; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     usernameEditText = (EditText) findViewById(R.id.main_username_editText); 
     passwordEditText = (EditText) findViewById(R.id.main_password_editText); 

     sendGetReqButton = (Button) findViewById(R.id.main_sendGetReq_button); 
     sendGetReqButton.setOnClickListener(this); 
    } 

    public void onClick(View v) { 

     if(v.getId() == R.id.main_sendGetReq_button) { 
      // Get the values given in EditText fields 
      String givenUsername = usernameEditText.getText().toString(); 
      String givenPassword = passwordEditText.getText().toString(); 
      System.out.println("Given usernames is :" + givenUsername + " Given password is :" + givenPassword); 

      // Pass those values to connectWithHttpGet() method 
      connectWithHttpGet(givenUsername, givenPassword); 
     }   
    } 

    private void connectWithHttpGet(String givenUsername, String givenPassword) { 

     class HttpGetAsyncTask extends AsyncTask<String, Void, String> { 

      @Override 
      protected String doInBackground(String... params) { 

       String email = params[0]; 
       String pwd = params[1]; 
       System.out.println("email is :" + email + " pwd is :" + pwd); 


       HttpClient httpClient = new DefaultHttpClient(); 


       HttpGet httpGet = new HttpGet("http://ipadress/folder/filename.php?command=CMD_LOGIN&email=name&pwd=00"); 

       try { 
        HttpResponse httpResponse = httpClient.execute(httpGet); 
        System.out.println("httpResponse"); 
        // that comes as the httpResponse 
        InputStream inputStream = httpResponse.getEntity().getContent(); 

        InputStreamReader inputStreamReader = new InputStreamReader(inputStream); 

        BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 
        StringBuilder stringBuilder = new StringBuilder(); 
        String bufferedStrChunk = null; 

        while((bufferedStrChunk = bufferedReader.readLine()) != null){ 
         stringBuilder.append(bufferedStrChunk); 
        } 
        System.out.println("Returning value of doInBackground :" + stringBuilder.toString()); 

        return stringBuilder.toString(); 
       } catch (ClientProtocolException cpe) { 
        System.out.println("Exception generates caz of httpResponse :" + cpe); 
        cpe.printStackTrace(); 
       } catch (IOException ioe) { 
        System.out.println("Second exception generates caz of httpResponse :" + ioe); 
        ioe.printStackTrace(); 
       } 

       return null; 
      } 

      @Override 
      protected void onPostExecute(String result) { 
       super.onPostExecute(result); 

       if(result.equals("1")) 
       { 

        Toast.makeText(getApplicationContext(), "HTTP GET is working...", Toast.LENGTH_LONG).show(); 
       }else{ 
        Toast.makeText(getApplicationContext(), "Invalid...", Toast.LENGTH_LONG).show(); 
       } 
      } 
     } 

     HttpGetAsyncTask httpGetAsyncTask = new HttpGetAsyncTask(); 

     httpGetAsyncTask.execute(givenUsername, givenPassword); 
    } 
} 

일치 한 후 인증 및 로그 캣에서 응답을받을 .which이 코드를 사용하여 로그인 페이지를 만드는거야 도와주세요 이렇게. 로그인 결과를 표시하기 위해 결과 값을 일치시키는 방법

if(result.equal("")) 

결과와 비교해야 할 사항은 무엇입니까? value==1으로 시도했지만 작동하지 않습니다. 데이터가 'HTTP 반환하는 경우

07-19 13:54:26.509: I/System.out(13951): Given usernames is :name Given password is :00 
07-19 13:54:26.519: I/System.out(13951): email is :name pwd is :00 
07-19 13:54:27.689: I/System.out(13951): httpResponse 
07-19 13:54:27.689: I/System.out(13951): Returning value of doInBackground :<?xml version="1.0" encoding="ISO-8859-1"?><command><value>1</value><email>[email protected]</email><id>100001</id><first_name>Sue</first_name><last_name>Stappler</last_name><photo>images/teacher.png</photo><total_students>2</total_students><student_list> <student>  <id>200001</id>  <first_name>John</first_name>  <last_name>Mathew</last_name>  <photo>images/student.png</photo> </student> <student>  <id>200002</id>  <first_name>Steve</first_name>  <last_name>Jobs</last_name>  <photo>images/student.png</photo> </student></student_list><description_title>Login Success</description_title><description_message>Correct username and password</description_message><session_id>ecaf065b3213179afcd0d9895691505c</session_id></command> 

답변

0

당신은 아마도 200 OK'

  • 데이터 확인이 요청의

    • HTTP 응답 코드
      • 확인이 개 상태를 확인할 수 있습니다
        • 응답을 비 직렬화 (SimpleXML, JacksonJson 또는 FasterXML pro ject) 직렬화 상태
        • 확인 (모델이 변경되거나 응답이 비어있는 경우, 아마 실패 할 것이다) 당신의 조건에 직렬화 된 객체의
        • 일치 필드
  • 관련 문제