您的位置:首页 > 移动开发 > Android开发

Android调用WEBSERVER发送信息到服务器

2016-07-28 17:51 453 查看
public void getgatherInfo(final String display,final String echoRoot,
final String isRootBySu,final String suProcess,final String isRootByFile,final String hard,
final String mem,final String ip,final String version,final String model,final String mac,
final String mac2) {

new Thread(new Runnable() {

@Override
public void run() {

// TODO Auto-generated method stub
// 命名空间
String nameSpace = "http://tempuri.org/";
// 调用方法的名称
String methodName = "gathers";
// EndPoint
String endPoint = "http://lajoin.jios.org:88/lajoin/Gather.asmx?op=gathers";
// SOAP Action
String soapAction = "http://tempuri.org/gathers";
// 指定WebService的命名空间和调用方法
SoapObject soapObject = new SoapObject(nameSpace, methodName);
// 设置需要调用WebService接口的两个参数mobileCode UserId
soapObject.addProperty("display", display);
soapObject.addProperty("echoRoot", echoRoot);
soapObject.addProperty("isRootBySu", isRootBySu);
soapObject.addProperty("suProcess", suProcess);
soapObject.addProperty("isRootByFile", isRootByFile);
soapObject.addProperty("hard", hard);
soapObject.addProperty("mem", mem);
soapObject.addProperty("ip", ip);
soapObject.addProperty("version", version);
soapObject.addProperty("model", model);
soapObject.addProperty("mac", mac);
soapObject.addProperty("mac2", mac2);

// 生成调用WebService方法调用的soap信息,并且指定Soap版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER10);
envelope.bodyOut = soapObject;
// 是否调用DotNet开发的WebService
envelope.dotNet = true;
envelope.setOutputSoapObject(soapObject);
HttpTransportSE transport = new HttpTransportSE(endPoint);
try {
transport.call(soapAction, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String result = object.getProperty(0).toString();
Message message = handler.obtainMessage();
message.obj = result;
handler.sendMessage(message);
}
}).start();

}

private Handler handler = new Handler(){
public void handleM
4000
essage(android.os.Message msg) {
// 将WebService得到的结果返回给TextView
if (msg.obj.toString().equals("true")) {
resultText.setText("盒子信息已成功上传服务器");

}else{
resultText.setText("盒子信息上传服务器失败!");
}

System.out.println("------------>"+msg.obj.toString());
};
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: