Import java.io.UnsupportedEncodingException;
Import Org.apache.commons.httpclient.Header;
Import org.apache.commons.httpclient.HttpClient;
Import Org.apache.commons.httpclient.NameValuePair;
Import Org.apache.commons.httpclient.methods.PostMethod;
public class Sendmsg_webchinese {
public static void Main (string[] args) throws Exception
{
HttpClient client = new HttpClient ();
Postmethod post = new Postmethod ("http://gbk.sms.webchinese.cn");
Post.addrequestheader ("Content-type", " APPLICATION/X-WWW-FORM-URLENCODED;CHARSET=GBK ");//Set transcoding
namevaluepair[] Data ={new Namevaluepair (" Uid "in the header file," Site user name "), New Namevaluepair (" Key "," Interface Security password "), New Namevaluepair (" Smsmob "," mobile phone number "), New Namevaluepair (" Smstext "," SMS Content ")} ;
Post.setrequestbody (data);
Client.executemethod (POST);
header[] headers = post.getresponseheaders ();
int statusCode = Post.getstatuscode ();
System.out.println ("StatusCode:" +statuscode);
for (Header h:headers)
{
System.out.println (h.tostring ());
}
String result = new String (post.getresponsebodyasstring (). GetBytes ("GBK"));
System.out.println (Result ); Print return message status
Post.releaseconnection ();
}
}
Jar Package Download
Commons-logging-1.1.1.jar
Commons-httpclient-3.1.jar
Commons-codec-1.4.jar
Java Send SMS SMS implementation interface