2012-02-29 43 views

回答

0

是的,你可以但你必须在http请求中传递soap xml,如下所示。 [消耗而不的Android ksoap2一个web服务的SOAP]的

public class SimpleHTTPRequest { 
    String envelope1="<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<soap:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"urn:insertdata\"" + 
    " targetNamespace=\"urn:insertdata\">"+ 
    "<soap:Body>"+ 
    "<insertdata>"+ 
    "<name xsi:type=\"xsd:string\">ghjghj</name>"+ 
    "<phone xsi:type=\"xsd:string\">1111</phone>"+ 
    "<email xsi:type=\"xsd:string\">ascom</email>"+ 
    "<score xsi:type=\"xsd:string\">12</score>"+ 
    "</insertdata>"+ 
    "</soap:Body>"+ 
    "</soap:Envelope>"; 
    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     String url="http://url/iphone_soap_server.php/insertdata"; 
      String soapAction="http://urkl/iphone_soap_server.php/insertdata/insertdata"; 
    HttpURLConnection connection = null; 
    OutputStreamWriter wr = null; 
    BufferedReader rd = null; 
    StringBuilder sb = null; 
    String line = null; 
    URL serverAddress = null; 
    String data = "width=50&height=100"; 
    try { 
     serverAddress = new URL("http://url/soap-server.php?wsdl"); 

     connection = null; 

     //Set up the initial connection 
     connection = (HttpURLConnection)serverAddress.openConnection(); 

     connection.setRequestMethod("POST"); 
     connection.setDoOutput(true); 

     connection.setDoOutput(true); 
     OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()); 


     writer.write(data); 
     writer.flush(); 




     rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
     sb = new StringBuilder(); 

     while ((line = rd.readLine()) != null) 
     { 
      sb.append(line + '\n'); 
     } 

     System.out.println(sb.toString()); 

    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (ProtocolException e1) { 
     e1.printStackTrace(); 
    } catch (IOException e2) { 
     e2.printStackTrace(); 
    } 
    finally 
    { 
     //close the connection, set all objects to null 
     connection.disconnect(); 
     rd = null; 
     sb = null; 
     wr = null; 
     connection = null; 
    } 
} 
} 
+0

感谢对于你的回复 – Venkat 2012-02-29 10:13:07

+0

你能发送任何Android相关的例子吗? thaks为你的回复 – Venkat 2012-02-29 10:33:57

+0

你需要使用HttpPost方法,而不是Httpurlconnection和相同的代码也将在Android中工作,因为Android支持基本的Java功能 – Maneesh 2012-02-29 10:49:36

相关问题