HttpClient for webservices
Soap client program
HttpClient for webservices
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.params.HttpMethodParams; import java.io.*; public class HttpClientTutorial { private static String url = "http://localhost:8087/NSAGTypes/services/NSAGReqResp"; public static void main(String[] args) { // Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. PostMethod method= new PostMethod(url); String abcd= "
"+ "
"+ "
"+ "
"+ "
"+ "
dasd
"+ "
"+ "
"+ "
dasda
"+ "
"+ "
"+ "
asdad
"+ "
"+ "
"+ "
"+ "
"+ "
"; // Provide custom retry handler is necessary // try { method.setRequestHeader("SOAPAction", "NSAGReqResp");//change this class name RequestEntity reqEntity = new ByteArrayRequestEntity(abcd.getBytes()); // Execute the method. method.setRequestEntity(reqEntity); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. String methodResoponse =method.getResponseBodyAsString(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data // System.out.println(new String(responseBody)); System.out.println(methodResoponse); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } } }
Please send comments to
vgdarur.javafive@blogger.com
Copyright © 2008 - iForeRunner.com
http://www.iforerunner.com/