<p><span>java send SMS messages, circulated there are several ways: (1) Use the WebService interface to send SMS, this can use the webservice provided by Sina to send, but need to register; (2) The use of text message Mao's way to send text messages, this way should be relatively common, the premise is the need to buy hardware equipment, hehe;</span></p>
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://sms.webchinese.cn/web_api/");
Post.addrequestheader ("Content-type",
"APPLICATION/X-WWW-FORM-URLENCODED;CHARSET=GBK");//Set transcoding in header file
namevaluepair[] data = {new Namevaluepair ("Uid", "* * * * *"),//Registered user name
New Namevaluepair ("Key", "*******"),//After successful registration, log in to the website using the key
New Namevaluepair ("Smsmob", "*********"),//Mobile phone number
New Namevaluepair ("Smstext", "Message from Java program!!")};
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);
Post.releaseconnection ();
}
}
Run the above code to achieve the ability to send text messages
SMS's official website: http://sms.webchinese.com.cn/api.shtml
Java Send SMS