2012-05-16 505 views
0

我正在開發一個android應用程序,我想將它連接到一個web服務, 關於如何創建一個web請求並接收響應的任何想法? N.B:我想將XML文件發送到Web服務並從中接收。 在此先感謝將android連接到網絡服務

+0

隨着web服務你是指SOAP Web服務? – rciovati

+0

http://stackoverflow.com/questions/1048310/how-to-call-a-net-web-service-from-android – Habib

回答

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 
       } 
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); 
}