为这个我也纠结了好多天
KSOAP2没有搞定
后来网上找到一个例子,用提交XML,返回XML再解析的方式,
复用性不高,不过想来因为少了很多中间步聚,效率反而好些吧
以下是代码try {
final String SERVER_URL = "http://10.3.254.199/sqlplus/Service.asmx"; // 定义需要获取的内容来源地址
URL url = new URL(SERVER_URL);
URLConnection con = url.openConnection();
con.setDoOutput(true);;
con.setRequestProperty("Pragma:", "no-cache");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Content-Type", "text/xml");
OutputStreamWriter out = new OutputStreamWriter(con
.getOutputStream());
// 控件取值
String xmlInfo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"+
"<soap12:Body>"+
"<CheckPWD xmlns=\"http://tempuri.org/\">"+
"<host>"+ etHost.getText().toString()+ "</host>"+
"<dbname>" +etdbname.getText().toString() + "</dbname>"+
"<uid>"+ etuid.getText().toString()+"</uid>"+
"<pwd>"+etpwd.getText().toString()+"</pwd>"+
"</CheckPWD>"+
"</soap12:Body></soap12:Envelope>";
// 发送
out.write(new String(xmlInfo.getBytes("UTF-8")));
out.flush();
out.close();
// 取返回值
//BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
//StringBuilder sBuilder = new StringBuilder();
//String line = "";
//for (line = br.readLine(); line != null; line = br.readLine())
//{
//sBuilder.append(line);
//}
//tvresult.setText(sBuilder);
//getResult解析XML
String s=getResult(con.getInputStream());
//return;
}
catch (java.lang.Exception e) {
tvresult.setText(e.getMessage());
}
提交的XML,参照你的WEB SERVIC 的说明
访问*.asmx?op=你的方法,就可以看到了你在百度 ANDROID 万能 WEBSERVIC
KSOAP2没有搞定
后来网上找到一个例子,用提交XML,返回XML再解析的方式,
复用性不高,不过想来因为少了很多中间步聚,效率反而好些吧
以下是代码try {
final String SERVER_URL = "http://10.3.254.199/sqlplus/Service.asmx"; // 定义需要获取的内容来源地址
URL url = new URL(SERVER_URL);
URLConnection con = url.openConnection();
con.setDoOutput(true);;
con.setRequestProperty("Pragma:", "no-cache");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Content-Type", "text/xml");
OutputStreamWriter out = new OutputStreamWriter(con
.getOutputStream());
// 控件取值
String xmlInfo = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"+
"<soap12:Body>"+
"<CheckPWD xmlns=\"http://tempuri.org/\">"+
"<host>"+ etHost.getText().toString()+ "</host>"+
"<dbname>" +etdbname.getText().toString() + "</dbname>"+
"<uid>"+ etuid.getText().toString()+"</uid>"+
"<pwd>"+etpwd.getText().toString()+"</pwd>"+
"</CheckPWD>"+
"</soap12:Body></soap12:Envelope>";
// 发送
out.write(new String(xmlInfo.getBytes("UTF-8")));
out.flush();
out.close();
// 取返回值
//BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
//StringBuilder sBuilder = new StringBuilder();
//String line = "";
//for (line = br.readLine(); line != null; line = br.readLine())
//{
//sBuilder.append(line);
//}
//tvresult.setText(sBuilder);
//getResult解析XML
String s=getResult(con.getInputStream());
//return;
}
catch (java.lang.Exception e) {
tvresult.setText(e.getMessage());
}
提交的XML,参照你的WEB SERVIC 的说明
访问*.asmx?op=你的方法,就可以看到了你在百度 ANDROID 万能 WEBSERVIC
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货