Java implementation to send mobile phone SMS _java

Source: Internet
Author: User

This paper mainly studies the Java language to send mobile phones, to share with you for your reference, the specific contents are as follows

Java to send mobile phone messages, there are several ways to circulate:

(1) Use WebService interface to send SMS, this can use the webservice provided by Sina to send, but need to register;
(2) The use of SMS Mao's way to send text messages, this way should be more commonly used, the premise is the need to buy hardware equipment, hehe;
(3) using the SMS platform provided by China Network, my small demo is based on this line is sent.

Description: Java implementation to send mobile phone text messages

/** * Description: Java implementation send SMS * Author: aa00aa00 * * Package com.test.mobile;
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 Ht
Tpclient ();
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 username new Namevaluepair ("Key", "*******")
Aluepair ("Smsmob", "*********"),//Mobile number new Namevaluepair ("Smstext", "Java program message!!")};
 
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: you can send a message to their mobile phone, I test, no problem, share to everyone!

The above is the entire content of this article, I hope to learn Java program to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.