url="https://192.168.1.127:7071/zimbraAdmin" public class NoCertificationHttpsGetSample {
public static void main(String[] args) {
Protocol myhttps = new Protocol("https",
new MySecureProtocolSocketFactory(),7071);
Protocol.registerProtocol("https", myhttps);
HttpClient httpClient = new HttpClient();
httpClient.getHostConfiguration().setHost("192.168 .1.127",7071,myhttps);
String url="https://192.168.1.127:7071/zimbraAdmin";
PostMethod postMethod = new PostMethod(url);
postMethod.getParams().setParameter(HttpMethodPara ms.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
try{
InputStream soap= new FileInputStream("soap.xml");
postMethod.setRequestBody(soap);
}catch(Exception err){};
try{
int statusCode = httpClient.executeMethod(postMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "+ postMethod.getStatusLine());
}
InputStream responseBody=postMethod.getResponseBodyAsStream();
System.out.println(responseBody);
} catch (HttpException e) {
System.out.println("Please check your provided https address!");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
postMethod.releaseConnection();
}
}
}
soap.xml like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra"/>
</soap:Header>
<soap:Body>
<AuthRequest xmlns="urn:zimbraAdmin">
<name>admin@sina.com</name>
<password>zimbra</password>
</AuthRequest>
</soap:Body>
</soap:Envelope>
error:
2006-3-23 13:21:06 org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded
信息: Redirect requested but followRedirects is disabled
Method failed: HTTP/1.1 302 Moved Temporarily
org.apache.commons.httpclient.AutoCloseInputStream @1cde100
Last edited by crossany; 07-05-2010 at 12:38 AM..
|