Created
March 2, 2011 17:36
-
-
Save justinedelson/851333 to your computer and use it in GitHub Desktop.
httpclient -> exodus
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
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