Dear developers,
I wanted to send data in a
java application to a
servlet which the servlet has a post() method to extract the data. My problem is the whole thing just doesn't work. Below is my codes and please kindly advise me on my problem.
--------------------------------------------------
import java.io.*;
import java.net.*;
public class StarhubSms{
private
String mobile = "90278850";
private String msg = "success";
private String host = "SHCORP";
public void startSms(){
try{
URL url = new URL("http://www.starhub.com.sg/servlet/SMSServlet");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches (false);
conn.setDefaultUseCaches (false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String message = "host="+URLEncoder.encode("SHCORP") + "&mobile="+URLEncoder.encode("90278850") +"&msg="+URLEncoder.encode("she");
BufferedWriter out =
new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
System.out.println(message+"\r\n");
out.write(message);
out.flush();
out.close();
System.out.println("Message sent!!");
}
catch(Exception e){}
}
}
-------------------------------------------------
Warmest regards,
Franco