使用Ksoap登录Android

时间:2011-04-11 16:35:04

标签: android login ksoap

我正在尝试使用kSoap登录Android应用程序。
这是我的代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    this.login = (Button) this.findViewById(R.id.btn_sign_in);
    this.login.setOnClickListener(new OnClickListener() {

        @Override
        // action of button
        public void onClick(View v) {

    username= (EditText)findViewById(R.id.txt_username);
    password= (EditText)findViewById(R.id.txt_password);
    String UserName = username.getText().toString();
    String Password = password.getText().toString();

    SoapObject loginRequest = new SoapObject(NAMESPACE, METHOD_NAME);
    loginRequest.addProperty("username", UserName);
    loginRequest.addProperty("password", Password);

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.dotNet=true;
    soapEnvelope.setOutputSoapObject(loginRequest);
    Log.i("LoginDetail", "Username " + UserName + "Password " + Password);

    HttpTransportSE aht = new HttpTransportSE(URL);
    aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

    FakeX509TrustManager.allowAllSSL(); // this class may allow SSL

    try{
        aht.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
        Log.i("OUTPUT", resultString.toString());
    }
     catch (XmlPullParserException ex) {
         String msg = ex.toString();
         System.out.println(msg);
         }  

    catch (Exception e){
        e.printStackTrace();
    }    

这就是我得到的:
04-11 16:01:39.705:INFO / System.out(521):org.xmlpull.v1.XmlPullParserException:意外类型(位置:TEXT在java.io.InputStreamReader @中没有... @ 1:50 44ec2250)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

请参阅this

这将解决您的问题。它用于使用SOAP Web服务对用户进行身份验证。