我正在开发一个Android应用程序,我想将它连接到一个Web服务, 有关如何发出Web请求并收到响应的任何想法? N.B:我想将一个XML文件发送到Web服务并从中接收。 提前致谢
答案 0 :(得分:0)
要连接网站,请使用以下代码
URL url = new URL("http://www.myweb.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000); // 5 seconds
conn.setRequestMethod("GET");
conn.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
//data of the page will be returned in line, do whatever u want here
}
答案 1 :(得分:0)
我创建了这个工具来自动生成wsdl到android代码,
http://www.wsdl2code.com/Example.aspx
public void callWebService(){
SampleService srv1 = new SampleService();
Request req = new Request();
req.companyId = "1";
req.userName = "userName";
req.password = "pas";
Response response = srv1.ServiceSample(req);
}