【问题标题】:How to authenticate an user through webservices in android?如何通过android中的Web服务对用户进行身份验证?
【发布时间】:2012-11-05 12:31:39
【问题描述】:

我对网络服务很陌生。目前我正在开发一个需要通过 web 服务对用户进行身份验证的 android 应用程序(意味着用户名和密码存储在远程数据库中)。谁能告诉我,我怎么能做到这一点?

【问题讨论】:

标签: android web-services webservice-client


【解决方案1】:

你可以使用 REST 网络服务请查看以下链接

Android Connecting to remote server Mysql

【讨论】:

    【解决方案2】:

    我不确定您使用的是什么网络服务。如果您的 Ksoap 2 网络服务。

    CheckNetwork C0de

     public class CheckNetwork {
    
    
    private static final String TAG = CheckNetwork.class.getSimpleName();
    
    
    
    public static boolean isInternetAvailable(Context context)
    {
        NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
           context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    
        if (info == null)
        {
             Log.d(TAG,"no internet connection");
             //Toast.makeText(context, "No Internet Connection", 1000);
             return false;
        }
        else
        {
            if(info.isConnected())
            {
                Log.d(TAG," internet connection available...");
                return true;
            }
            else
            {
                Log.d(TAG," internet connection");
                return true;
            }
    
        }
    }
     }
    

    在你的活动中 onCreate()

      Name =mEditTextUsername.getText().toString();
      Pass= mEditTextPassword.getText().toString();
      new TheTask().execute(Name,Pass);
    
    class TheTask extends AsyncTask<String, Integer, Void>{
        ProgressDialog pd;
    
        @Override
        protected void onPreExecute() {
            pd=new ProgressDialog(Login.this);
            pd.setTitle("Authenticating");
            pd.show();
    
        }
    
        @Override
        protected Void doInBackground(String... params) {   
            authenticate(params[0],params[1]);
            return null;
    
        }
    
        @Override
        protected void onPostExecute(Void result) {
            pd.dismiss();
           }
        public void authenticate(String name, String pass)
        {
        if(CheckNetwork.isInternetAvailable(Login.this))
        {
    
            SoapObject request = new SoapObject("NameSpace", "method name");
                    PropertyInfo loginreq = new PropertyInfo();
            loginreq.name="LoginReq";
            loginreq.type=String.class;
                        loginreq.setValue(your request value);
                        request.addProperty(loginreq);  
                SoapSerializationEnvelope envelop = new      SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelop.setOutputSoapObject(request);
                System.out.println("Request is"+request); 
    
            HttpTransportSE androidHttpTransport = new   HttpTransportSE ("your wsdl link");
            androidHttpTransport.debug=true;                                                                  androidHttpTransport.call("YOUR LOGINREQUST", envelop);
            SoapObject response=(SoapObject) envelop.bodyIn;
            System.out.println("Response is......"+response.toString());//get your response
        }   
    

    Webservice 使用代码标记 1 表示成功,0 表示失败。这也取决于webservice响应的设计。 上面的代码使用soap webservice工作。也看看这个链接。 how to connect android and mysql server?.

    【讨论】:

      猜你喜欢
      • 2011-10-16
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 2015-01-14
      • 2012-05-25
      • 2016-01-27
      相关资源
      最近更新 更多