Created
May 11, 2012 01:39
-
-
Save jtuberville/2656965 to your computer and use it in GitHub Desktop.
How to urlencode using HttpClient
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
public static String sendViaHttpClient(String userName, String apiKey, String from, String fromName, String subject, String body, String to) { | |
NameValuePair[] data = { | |
new BasicNameValuePair("userName", userName), | |
new BasicNameValuePair("api_key", apiKey), | |
new BasicNameValuePair("from", from), | |
new BasicNameValuePair("from_name", fromName), | |
new BasicNameValuePair("subject", subject), | |
new BasicNameValuePair("body_html", body), | |
new BasicNameValuePair("to", to) | |
}; | |
try { | |
org.apache.http.client.HttpClient client = new DefaultHttpClient(); | |
HttpPost post = new HttpPost("https://api.elasticemail.com/mailer/send"); | |
post.setEntity(new UrlEncodedFormEntity(data)); | |
HttpResponse response = client.execute(post); | |
System.out.println(response); | |
} catch (URISyntaxException e) { | |
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | |
} catch (HttpException e) { | |
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | |
} catch (InterruptedException e) { | |
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | |
} catch (IOException e) { | |
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment