0

我正在开发一个 android 应用程序,我想将它连接到一个网络服务,关于如何发出网络请求和接收响应的任何想法?注意:我想将一个 XML 文件发送到 Web 服务并从中接收。提前致谢

4

2 回答 2

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
                }
于 2012-05-16T14:18:43.293 回答
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);
}
于 2012-12-06T06:03:28.137 回答