Created
September 19, 2012 22:50
-
-
Save SidneyAllen/3752855 to your computer and use it in GitHub Desktop.
SendGrid StackMob - Build URL and POST
This file contains 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
//Encode any parameters that need encoding (i.e. subject, toname, text) | |
try { | |
subject = URLEncoder.encode(subject, "UTF-8"); | |
text = URLEncoder.encode(text, "UTF-8"); | |
toname = URLEncoder.encode(toname, "UTF-8"); | |
} catch (UnsupportedEncodingException e) { | |
logger.error(e.getMessage(), e); | |
} | |
String queryParams = "api_user=" + API_USER + "&api_key=" + API_KEY + "&to=" + to + "&toname=" + toname + "&subject=" + subject + "&text=" + text + "&from=" + from; | |
url = "https://www.sendgrid.com/api/mail.send.json?" + queryParams; | |
Header accept = new Header("Accept-Charset", "utf-8"); | |
Header content = new Header("Content-Type", "application/x-www-form-urlencoded"); | |
Set<Header> set = new HashSet(); | |
set.add(accept); | |
set.add(content); | |
try { | |
HttpService http = serviceProvider.getHttpService(); | |
PostRequest req = new PostRequest(url,set,body); | |
HttpResponse resp = http.post(req); | |
responseCode = resp.getCode(); | |
responseBody = resp.getBody(); | |
} catch(TimeoutException e) { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment