I have this string representing a XML:
String soapCall=\"
Formatted answer :
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
/**
* * This program demonstrates consuming web service using Apache HTTPClient and
* SOAP message. * Reference:
* http://www.webservicex.net/stockquote.asmx?op=GetQuote * ClassPath: Keep these
* two files in class path: commons-httpclient-3.0.1.jar, commons-codec-1.4.jar * @author
* Bhavani P Polimetla * @since April-27-2011
*/
public class WSClient {
public static void main(String args[]) {
HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter("http.useragent",
"Web Service Test Client");
BufferedReader br = null;
String data = " "
+ " "
+ " "
+ " "
+ "INFY " + " "
+ " ";
PostMethod methodPost = new PostMethod(
"http://www.webservicex.net/stockquote.asmx?op=GetQuote");
methodPost.setRequestBody(data);
methodPost.setRequestHeader("Content-Type", "text/xml");
try {
int returnCode = httpClient.executeMethod(methodPost);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.out
.println("The Post method is not implemented by this URI");
methodPost.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(
methodPost.getResponseBodyAsStream()));
String readLine;
while (((readLine = br.readLine()) != null)) {
System.out.println(readLine);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
methodPost.releaseConnection();
if (br != null) try {
br.close();
} catch (Exception fe) {
fe.printStackTrace();
}
}
}
}