Java sends messages to your phone via code

Source: Internet
Author: User

One, the code
Import Java.io.ioexception;import Org.apache.commons.httpclient.header;import Org.apache.commons.httpclient.httpclient;import Org.apache.commons.httpclient.httpexception;import Org.apache.commons.httpclient.namevaluepair;import Org.apache.commons.httpclient.methods.postmethod;public Class Sendmsg_webchinese {public static void main (string[] args) throws HttpException, IOException {HttpClient client = new Http Client (); Postmethod post = new Postmethod ("http://gbk.sms.webchinese.cn");//Postmethod post = new//Postmethod ("http:// sms.webchinese.cn/web_api/");p ost.addrequestheader (" Content-type "," application/x-www-form-urlencoded;charset= GBK ");//Set transcoding in header file namevaluepair[] data = {new Namevaluepair (" Uid "," Registered user name "),//registered user name New Namevaluepair (" Key "," after registering successfully, Login to the website to get the key "),//After the successful registration, login to the site after the key new Namevaluepair (" Smsmob "," mobile phone number "),//mobile number multiple to", "separated as 12345678900,12365498700new Namevaluepair ("Smstext", "SMS Content")};//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);}}
Second, the project needs the jar package

Commons-logging-1.1.1.jar
: Http://pan.baidu.com/s/1CSonc
Commons-httpclient-3.1.jar
: http://pan.baidu.com/s/1sjjXy6x
Commons-codec-1.4.jar
: Http://pan.baidu.com/s/1eQGhVhS

Java sends messages to your phone via code

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.