Hi
i make a simple
servlet which send msg to
www.SmsSite.com/SmsScript.asp it connects but not send msg.i am using this servlet to use in my computer for getting simple parameters and it is working fine. i think there is no problem with parameters values of mine and SmsSite cause i send msg using simple form from my desktop and it is working fine.pls help me.
it is working fine
<form method=POST action="http://www.SmsSite.com/SmsScript.asp" name="SMS">
<input type="hidden" name="email" value="SMS-Daemon@vxt.com">
<input type="hidden" name="recipient" value="sms@vxt.com">
<TEXTAREA NAME=MESSAGE ROWS=5 COLS=35></TEXTAREA>
<input type="text" name="PHONE" size="10" maxlength="8">
<INPUT TABINDEX="10" MAXLENGTH=3 SIZE=2 VALUE="150" NAME="smsLEFT" readOnly>
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Send" >
</form>
There is some problem in it.it connects but not send any msg.
import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Sms extends HttpServlet implements Runnable {
Thread thread;
URL url;
public void init() {
try {
System.out.println("Init");
thread=new Thread(this);
}
catch(Exception e){System.out.println("Error: "+e);}
}
public void doGet(HttpServletRequest req,HttpServletResponse res) {
thread.start();
}
public void run() {
try {
while(true) {
System.out.println("Sending Msg At : "+new Date());
sendSms();
thread.sleep(60*500);
}
}
catch(InterruptedException ie) {System.out.println("InterruptedException :"+ie);}
}
private void sendSms() {
try {
System.out.println("Connecting.....");
URL cellUrl = new URL("www.SmsSite.com/SmsScript.asp");
HttpURLConnection con = (HttpURLConnection) cellUrl.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
String x ="email=SMS-Daemon@vxt.com&recipient=sms@vxt.com&MESSAGE=yahoo&PHONE=2142816&smsLEFT=150&SUBMIT=Send";
con.setRequestProperty("CONTENT_LENGTH", "" + x.length());
OutputStream os = con.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(x);
osw.flush();
osw.close();
InputStream is = con.getInputStream();
System.out.println("Msg Has Been Sent");
}
catch(Exception ie) {System.out.println("InterruptedException :"+ie);}
}
}