Hi all , i had a requirement of implementing sms gateway in our application to send sms. I worked on that and i would like to share that piece of code.
Depending on the SMS service provider api the implementation methodology may also change. Generally it can be implemented in two ways either using http service or smtp service.
I will provide the example of using http service.
void httpsTry() {
HttpClient client = new HttpClient();
//client.getParams().setParameter("http.useragent", "Test Client");
BufferedReader br = null;
PostMethod method = new PostMethod("api url");
String to1[] = {"00000000", "00000000"};
try {
for (int i = 0; i < to1.length; i++) {
method.addParameter("user", "\"test\"");
method.addParameter("pass", "\"test\"");
method.addParameter("phonenumber", "\"" + to1[i] + "\"");
method.addParameter("subject", "\"test\"");
method.addParameter("message", "\"test from dev team\"");
int returnCode = client.executeMethod(method);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.err.println("The Post method is not implemented by this URI");
// still consume the response body
method.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
String readLine;
while (((readLine = br.readLine()) != null)) {
// System.err.println(readLine);
System.out.println("out put-->" + readLine);
}
}
}
} catch (Exception e) {
System.err.println(e);
} finally {
method.releaseConnection();
if (br != null) {
try {
br.close();
} catch (Exception fe) {
}
}
}
}
6/25/10
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Hi folks, I got a chance to work with JSF, it was an interesting requirement. Its about a custom component which would be of more use to ...
-
Hi Folks, I would like to share my another POC task in JSF with you all. "Primefaces Dropdown with Pagination & Filter "...
-
We shall create temp table in mysql using the sql script CREATE TEMPORARY TABLE testraghu(name VARCHAR(50) , phone VARCHAR(50)) Let us se...
-
Hi all, i would like to share a simple example of storing haspmap in mysql db. In order to store object into your db, the field type must ...
No comments:
Post a Comment