在Android中使用Web服务
本文关键字:Web 服务 Android | 更新日期: 2023-09-27 18:19:35
我需要将数据发送到用c#.net编写的web服务,如果我使用c#
程序,它可以获得web服务的名称和我想我可以使用的函数是java
,它不能做同样的事情作为c#
,如果有人知道如何做到这一点,那就太好了。谢谢你的帮助!
我使用httpURLConnection
并编写此代码来发送和获取响应从连接。
BufferedReader reader = null;
try {
URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line + ''n');
}
Log.i("","here "+sb.toString());
return sb.toString();
} catch (Exception e) {
Log.i("","problem in connection");
return null;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
如果我没有错的话,C#web服务使用SOAP协议,因此您可能需要解析SOAP响应,该响应将提供有关web服务api的信息:检查此线程:分析android 中的SoapObject Respons