2011-08-14 8 views
0

Androidサービス内からユーザー認証のためにWebサービスを呼び出す際に問題が発生しました。私は、ユーザー名とパスワードを入力すると、私は知っている権利です、それは私に奇妙なXMLエラーを与えているエミュレータ画面上ユーザー認証WebサービスコードがAndroidアプリケーションから実行されていません

ここに私のAndroidのコードされています

  package com.demo; 
      import android.app.Activity; 
      import android.os.Bundle; 
      import java.io.BufferedReader; 
      import java.io.IOException; 
      import java.io.InputStream; 
      import java.io.InputStreamReader; 
      import java.util.ArrayList; 
      import java.util.List; 

      import org.apache.http.HttpResponse; 
      import org.apache.http.NameValuePair; 
      import org.apache.http.client.ClientProtocolException; 
      import org.apache.http.client.HttpClient; 
      import org.apache.http.client.entity.UrlEncodedFormEntity; 
      import org.apache.http.client.methods.HttpPost; 
      import org.apache.http.impl.client.DefaultHttpClient; 
      import org.apache.http.message.BasicNameValuePair; 

      //import android.app.Activity; 
      //import android.os.Bundle; 
      import android.util.Log; 
      import android.view.View; 
      import android.view.View.OnClickListener; 
      import android.widget.Button; 
      import android.widget.EditText; 
      import android.widget.TextView; 

      public class AndroidLogin extends Activity implements OnClickListener { 
      /** Called when the activity is first created. */ 
      Button ok,back,exit; 
      TextView result; 
      @Override 
       public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ok =(Button)findViewById(R.id.btn_login); 
      ok.setOnClickListener(this); 

      result = (TextView)findViewById(R.id.lbl_result); 

     } 

      public void postLoginData() { 
      // Create a new HttpClient and Post Header 
      HttpClient httpclient = new DefaultHttpClient(); 


     HttpPost httppost = new HttpPost("http://10.0.2.2/testlogin/Service1.asmx"); 

      try { 
     // Add user name and password 
    EditText uname = (EditText)findViewById(R.id.txt_username); 
    String username = uname.getText().toString(); 

    EditText pword = (EditText)findViewById(R.id.txt_password); 
    String password = pword.getText().toString(); 

     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
     nameValuePairs.add(new BasicNameValuePair("username", username)); 
     nameValuePairs.add(new BasicNameValuePair("password", password)); 
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

     // Execute HTTP Post Request 
     Log.w("demo", "Execute HTTP Post Request"); 
     HttpResponse response = httpclient.execute(httppost); 

     String str = inputStreamToString(response.getEntity().getContent()).toString(); 
     Log.w("demo", str); 

     if(str.toString().equalsIgnoreCase("true")) 
     { 
     Log.w("demo", "TRUE"); 
     result.setText("Login successful"); 
     }else 
     { 
     Log.w("demo", "FALSE"); 
     result.setText(str);    
     } 

    } catch (ClientProtocolException e) { 
    e.printStackTrace(); 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
} 

     private StringBuilder inputStreamToString(InputStream is) { 
     String line = ""; 
     StringBuilder total = new StringBuilder(); 
// Wrap a BufferedReader around the InputStream 
     BufferedReader rd = new BufferedReader(new InputStreamReader(is)); 
// Read response until the end 
     try { 
      while ((line = rd.readLine()) != null) { 
      total.append(line); 
    } 
     } catch (IOException e) { 
     e.printStackTrace(); 
     } 
// Return full string 
     return total; 
     } 

@Override 
public void onClick(View view) { 
    if(view == ok){ 
    postLoginData(); 
    } 
} 
    } 

ここでは私の出力の写真ですエミュレータ上:ここhttp://www.flickr.com/photos/[email protected]/6041731494/ はlogcatです:http://pastebin.com/YmH0h6SF

誰かが私は.NETの専門家でありませんが、logcatのログから、何かは、サーバー側で間違っているようだ

+0

サービスから返された例外を読みます。私はそれを行うことはできませんあなたはそれがカットされて提供されたスクリーンショットです。 – pkk

+0

@pkk:完全なものを見ることさえできません.uは、私のログカットを確認できます。もしエミュレータ画面のサイズを増やす方法があれば、隠されたものを見ることができます。 –

+0

logcatを使ってログに記録します。メッセージを編集し、投稿を編集してそこに追加します:Log.d( "tag"、str); Log.w( "demo"、 "FALSE")の近くにあります。 – pkk

答えて

関連する問題