Java Programming Example

The following is an example of Java code used for HTTPS Post.

PostMethod and HttpClient are both part of the Apache HttpClient library located at http://jakarta.apache.org/commons/httpclient/.

 

PostMethod post = new PostMethod(url); // url = fully qualified url of the server to which you are posting

post.setRequestHeader("Content-type", "text/xml; charset=UTF-8");

post.setRequestBody(data); //data = request data in XML format

 

HttpClient client = new HttpClient();

client.setTimeout(10000); //10 second timeout (in milliseconds) is suggested minimum, 30 second recommended for alternate payment methods

client.executeMethod(post);

 

String response = post.getResponseBodyAsString();

 

//if the server throws an exception you get a null response

//to get around this set it to "" if (response == null) {

response = "";

}

post.releaseConnection();