Skip to content

Instantly share code, notes, and snippets.

@justinedelson
Created March 2, 2011 17:36
Show Gist options
  • Save justinedelson/851333 to your computer and use it in GitHub Desktop.
Save justinedelson/851333 to your computer and use it in GitHub Desktop.
httpclient -> exodus
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HttpPostBody {
private static Log log = LogFactory.getLog(HttpPostBody.class);
public static void main(String[] args) {
String strongmailXml = "REDACTED";
int resp = sendNewsletterSelections(strongmailXml);
System.out.println(resp);
}
private static int sendNewsletterSelections(String strongmailXml) {
String url = "REDACTED";
try {
HttpClient hc = new HttpClient();
hc.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
hc.getHttpConnectionManager().getParams().setSoTimeout(1000);
PostMethod pm = new PostMethod(url);
pm.setRequestEntity(new StringRequestEntity(strongmailXml, "application/xml", "UTF-8"));
int resp = hc.executeMethod(pm);
if (resp != HttpStatus.SC_OK) {
log.error("Unexpected response code from Exodus: " + resp + ". Response body: "
+ pm.getResponseBodyAsString());
}
return resp;
} catch (Exception e) {
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment