2011-06-22 64 views

回答

1

這不是休息,但即使是Zimbra的SOAP API,但它是一個解決方案:

  URL url = new URL(SOAPUrl); 
     URLConnection connection = url.openConnection(); 
     HttpURLConnection httpConn = (HttpURLConnection) connection; 

     String postContent = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">"+ 
     "<soap:Header>" + 
     "<context xmlns=\"urn:zimbra\">" + 
     "<format type=\"js\"/>" + 
     "<authToken>" + authToken + "</authToken>" + 
     "</context>" + 
     "</soap:Header>" + 
     "<soap:Body>" + 
     "<GetFolderRequest xmlns=\"urn:zimbraMail\" />" + 
     "</soap:Body>" + 
     "</soap:Envelope>"; 

     // insert your SOAP XML!!! 
     byte[] b = postContent.getBytes(); 

     // Set the appropriate HTTP parameters. 
     httpConn.setRequestProperty("Content-Length", String.valueOf(b.length)); 
     httpConn.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8"); 
     httpConn.setRequestMethod("POST"); 
     httpConn.setDoOutput(true); 
     httpConn.setDoInput(true); 

     // Everything's set up; send the XML that was read in to b. 
     OutputStream out = httpConn.getOutputStream(); 
     out.write(b); 
     out.close(); 

     // Read the response and write it to standard out. 
     InputStreamReader isr = new InputStreamReader(httpConn.getInputStream()); 
     BufferedReader in = new BufferedReader(isr); 

     // read & do something with input stream... 
     String s = null; 
     String soapResponse = ""; 
     while((s=in.readLine()) != null){ 
      soapResponse += s; 
     } 
     System.out.println(soapResponse); 

當你解析結果,採取符合你想要什麼(任命文件夾... )

+0

嗨,我還需要獲得日曆名稱...什麼是「的authToken」變量? – startupsmith

相關問題