//Replace highlighted in yellow variables as per your requirement.
import java.io.File;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
public class PostSOAP {
public static void main(String[] args) throws Exception {
String strURL="END_POINT";
String strSoapAction = "SOAP-ACTION";
String strXMLFilename = "REQUEST.xml";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient client = new HttpClient();
try {
int returnCode = client.executeMethod(post);
//To print the http response code.. 200 for success.
System.out.println("Response status code: " + returnCode);
//To print the output.
System.out.println(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
}
import java.io.File;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
public class PostSOAP {
public static void main(String[] args) throws Exception {
String strURL="END_POINT";
String strSoapAction = "SOAP-ACTION";
String strXMLFilename = "REQUEST.xml";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient client = new HttpClient();
try {
int returnCode = client.executeMethod(post);
//To print the http response code.. 200 for success.
System.out.println("Response status code: " + returnCode);
//To print the output.
System.out.println(post.getResponseBodyAsString());
} finally {
post.releaseConnection();
}
}
}