Last active
December 16, 2015 05:19
-
-
Save andrewnguyen42/5384029 to your computer and use it in GitHub Desktop.
Send an xml string to a url Requires 5 jars: commons-httpclient-3.0.1.jar ,
httpclient-4.0-alpha2.jar ,
httpcore-4.0-alpha6.jar ,
commons-codec-1.7.jar ,
commons-logging-1.1.2.jar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Actually takes care of posting data to a service | |
* @param xml The xml data in the form of a Java String | |
* @param url The address to post data to | |
*/ | |
private static boolean postData(String xml, String url){ | |
//PostMethod post=new PostMethod(); | |
HttpPost pst=null; | |
try { | |
//build headers and body of post request | |
pst=new HttpPost(url); | |
StringEntity requestEntity = new StringEntity(xml); | |
pst.setEntity(requestEntity); | |
pst.setHeader("Content-type", | |
"text/xml; charset=ISO-8859-1"); | |
DefaultHttpClient httpClient = new DefaultHttpClient(); | |
//TODO use this response to give our client a message | |
HttpResponse response=httpClient.execute(pst); | |
int statusCode=response.getStatusLine().getStatusCode(); | |
return statusCode>=400&&statusCode<=499; | |
}catch (org.apache.http.HttpException| URISyntaxException|IOException | InterruptedException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment