我是新来的android请帮助我。
这是我试过的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
btnLogin=(Button)findViewById(R.id.btnLogin);
btnCancel=(Button)findViewById(R.id.btnCancel);
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
username=(EditText)findViewById(R.id.et_un);
password=(EditText)findViewById(R.id.et_pwd);
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);>
如何传递请求参数?
PropertyInfo p1=new PropertyInfo()
p1.setName("username");
p1.setValue("nitinr");
request.addProperty(p1);
PropertyInfo p2=new PropertyInfo();
p2.setName("password");
p2.setValue("123");
request.addProperty(p2);
如何为此编码? 我不知道如何解析响应的输出? 并指导将会有什么回应?
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
//invkoe web service and get result
try {
httpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
tv.setText(response.toString());
} catch (Exception exception) {
tv.setText(exception.toString());
}
if(username.equals("nitinr")){
if(password.equals("123")){
onClick(v);
} else{
lblResult.findViewById(R.id.tv_link);
}
}else{
btnLogin.findViewById(R.id.tv_valid)
}
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(getBaseContext(),Welcome.class);
startActivity(i);
}
}
答案 0 :(得分:1)
如果您使用的是Http请求方法,请使用此链接... Httprequest
答案 1 :(得分:0)
如果您正在使用soap webservice,那么您需要检查您的服务以获取您正在呼叫的服务操作的响应。
e.g。成功登录时可能返回1,无效用户或密码返回-1,用户不存在0。
/**
* Login web services to authenticate the user.
* @param Uname
* @param Pword
* @return
*/
public static int loginCheck(String Uname, String Pword){
int id= 0;
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,SOAPLOGINMETHOD);
request.addProperty("username",Uname);
request.addProperty("password",Pword);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try{
httpTransport.call(SOAPLOGINACTION, envelope);
SoapObject response=(SoapObject) envelope.bodyIn;
Log.d("parameter", response.getProperty(0).toString());
id=Integer.parseInt(response.getProperty(0).toString());
}
catch (Exception exception){
Log.d("Login Web Service Exception",exception.toString());
exception.printStackTrace();
}
return id;
}
使用return as:
public void onLoginClick(View view){
userName=userNameTxt.getText().toString();
password=passwordTxt.getText().toString();
int uId=WebMethod.loginCheck(userName, password);
if(uId >0){
// Do what you want with it
}