[英]Connecting android to a web-service
I am developing an android application, I want to connect it to a web-service , Any ideas about how to make a web request and receive the response? 我正在开发一个android应用程序,我想将其连接到Web服务,关于如何发出Web请求并接收响应的任何想法? NB: I want to sen a XML file to the web-service and receive from it too.
注意:我想将XML文件发送到Web服务并从中接收。 Thanks in advance
提前致谢
For connecting a website use the following code 要连接网站,请使用以下代码
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
}
i founded this tool to auto generate wsdl to android code, 我创建了这个工具来自动将wsdl生成为android代码,
http://www.wsdl2code.com/Example.aspx 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.