Implementation of the SMS interface for China Internet

Source: Internet
Author: User

The implementation is relatively simple. Just send the mobile phone number and content to a specific URL. The Code is as follows:

Public String sendsms (string mobile, string content) {string username = "Account"; // string Password = "password "; // provide the password string url = "http://utf8.sms.webchinese.cn"; // path string result = ""; int Re = 0; try {httpwebrequest request = (httpwebrequest) webrequest. create (URL); Request. method = "Post"; request. contenttype = "application/X-WWW-form-urlencoded"; stringbuilder buffer = new stringbuilder (); buff Er. appendformat ("uid = {0}", username); buffer. appendformat ("& Key = {0}", password); buffer. appendformat ("& smsmob = {0}", mobile); buffer. appendformat ("& smstext = {0}", httputility. urlencode (content + "[internal management system]", encoding. utf8); byte [] DATA = encoding. utf8.getbytes (buffer. tostring (); Using (Stream stream = request. getrequeststream () {stream. write (data, 0, Data. length);} httpwebresponse response = (HT Tpwebresponse) request. getresponse (); streamreader sr = new streamreader (response. getresponsestream (), encoding. utf8); string MSG = sr. readtoend (); Sr. close (); Int. tryparse (MSG, out re); If (Re <= 0) {result = "SMS sending failed! Error Code: "+ MSG;} else {result =" sms sent successfully ";}} catch (exception ex) {result =" SMS failed to be sent! Error message: "+ ex;} return result ;}

 

Related Article

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.