Enterprise SMS via C # HTTP interface send SMS

Source: Internet
Author: User
Tags md5 encryption

/* Function: Enterprise SMS through C # HTTP interface send SMS Modified Date: 2014-09-01 Description: http://api.cnsms.cn/?ac=send&uid= user account &pwd=md5 bit 32 password &mobile= Number &content= content Status: 100 Send Success 101 authentication failed 102 SMS less than 103 operation failed 104 illegal character 105 content too 106th number too 107 frequency too fast 108th code content empty 109 account Freeze 110 prohibit frequent single send 111 system tentative Send 112th number is incorrect 120 system upgrade */Using System;Using System.Text;Using System.Net;Using System.IO;Using System.Data;Namespace esmstest{Class Sendesms {Staticvoid Main (String[] (args) {String strcontent ="Enterprise SMS Pass Test C #";GET mode String Getreturn = Dogetrequest ("Http://api.cnsms.cn/?ac=send&uid=100226&pwd=fa246d0262c3925617b0c72bb20eeb1d&mobile= 13585519197,13900008888&content= "+ strcontent); Console.WriteLine ("Get response is:" + Getreturn); StringBuilder sbtemp =New StringBuilder ();POST Sbtemp.append ("ac=send&uid=70299999&pwd=fa246d0262c3925617b0c72bb20eeb1d&mobile=13339196131,15375379376& Content= "+ strcontent);byte[] btemp = Encoding.ASCII.GetBytes (sbtemp.tostring ()); String Postreturn = Dopostrequest ("http://api.cnsms.cn/", btemp); Console.WriteLine ("Post response is:" + Postreturn);}Post method sent resultsPrivateStatic String Dopostrequest (String URL,Byte[] bdata) {System.Net.HttpWebRequest hwrequest; System.Net.HttpWebResponse Hwresponse;String strresult = String. Empty;try {hwrequest = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (URL); hwrequest.timeout =5000; Hwrequest.method ="POST"; Hwrequest.contenttype ="Application/x-www-form-urlencoded"; Hwrequest.contentlength = Bdata.length; System.IO.Stream smwrite = Hwrequest.getrequeststream (); Smwrite.write (Bdata,0, Bdata.length); Smwrite.close (); }catch (System.Exception err) {Writeerrlog (err. ToString ());return strresult; }Get responsetry {hwresponse = (HttpWebResponse) hwrequest.getresponse (); StreamReader Srreader =New StreamReader (Hwresponse.getresponsestream (), encoding.ascii); strresult = Srreader.readtoend (); Srreader.close (); Hwresponse.close (); }catch (System.Exception err) {Writeerrlog (err. ToString ()); }return strresult; }Results sent by Get modePrivateStatic String Dogetrequest (String url) {HttpWebRequest hwrequest; HttpWebResponse Hwresponse;String strresult = String. Empty;try {hwrequest = (System.Net.HttpWebRequest) webrequest.create (URL); hwrequest.timeout =5000; Hwrequest.method ="GET"; hwrequest.contenttype = "application/x-www-form-urlencoded";} catch (System.Exception err) {Writeerrlog (err. ToString ()); return strresult;} //get Response try {hwresponse = (HttpWebResponse) hwrequest.getresponse (); StreamReader Srreader = new StreamReader (Hwresponse.getresponsestream (), encoding.ascii); strresult = Srreader.readtoend (); Srreader.close (); Hwresponse.close (); } catch (System.Exception err) {Writeerrlog (err. ToString ()); } return strresult;} private static void Writeerrlog (string strerr) {Console.WriteLine (strerr); System.Diagnostics.Trace.WriteLine (STRERR); } }}

return result copy
100

Get Balance Request Replication
/* Function: Enterprise SMS through C # HTTP interface take balance modification Date: 2014-09-01 Description: http://api.cnsms.cn/?ac=gc&uid= user account &pwd=md5 bit 32 password status: 100 Send Success 101 Authentication failed 102 SMS less than 103 operation failed 104 illegal character 105 content too many 106th code too 107 frequency too fast 108th code content empty 109 account freezes 110 prohibit frequent single send 111 system tentative send 112th code incorrect 120 system upgrade */Using System;Using System.Collections;Using System.Configuration;Using System.Data;Using System.Linq;Using System.Web;Using System.Web.Security;Using System.Web.UI;Using System.Web.UI.HtmlControls;Using System.Web.UI.WebControls;Using System.Web.UI.WebControls.WebParts;Using System.Xml.Linq;Using Present.model;Using Present.dal;Using PRESENT.BLL;Using System.Data.SqlClient;Using System.Text;Using System.Net;Using System.IO;Using System.Globalization;Using System.Security.Cryptography;PublicPartialClass _default:system.web.ui.page{#Region SMS SendProtectedvoid Button2_Click (Object sender, EventArgs e) {String uid="100226";User nameString pass ="100226";Password StringBuilder sbtemp =New StringBuilder ();p the Formsauthentication.hashpwdforstoringinconfigfile (pass,"MD5");Password for MD5 encryptionPOST Pass Value Sbtemp.append ("Ac=gc&uid=" +uid+"&pwd=" + Pass);byte[] Btemp = System.Text.Encoding.GetEncoding ("GBK"). GetBytes (Sbtemp.tostring ()); String Postreturn = Dopostrequest ("http://api.cnsms.cn/", btemp); Response.Write ("Post response is:" + Postreturn);Test return result}Post method sent resultsPrivateStatic String Dopostrequest (String URL,Byte[] bdata) {System.Net.HttpWebRequest hwrequest; System.Net.HttpWebResponse Hwresponse;String strresult = String. Empty;try {hwrequest = (System.Net.HttpWebRequest) System.Net.WebRequest.Create (URL); hwrequest.timeout =5000; Hwrequest.method ="POST"; Hwrequest.contenttype ="Application/x-www-form-urlencoded"; Hwrequest.contentlength = Bdata.length; System.IO.Stream smwrite = Hwrequest.getrequeststream (); Smwrite.write (Bdata,0, bdata.length); Smwrite.close (); } catch (System.Exception err) {Writeerrlog (err. ToString ()); return strresult;} //get response try {hwresponse = (HttpWebResponse) hwrequest.getresponse (); StreamReader Srreader = new StreamReader (Hwresponse.getresponsestream (), encoding.ascii); strresult = Srreader.readtoend (); Srreader.close (); Hwresponse.close (); } catch (System.Exception err) {Writeerrlog (err. ToString ()); } return strresult;} private static void writeerrlog ( string strerr) {Console.WriteLine (strerr); System.Diagnostics.Trace.WriteLine (STRERR); } #endregion}         

return result copy
100| | 22348

Enterprise SMS via C # HTTP interface send SMS

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.