C # code implementation SMS Authentication Code interface Sample _c# Tutorial

Source: Internet
Author: User

This example for you to share the C # implementation of the SMS Authentication Code interface examples for your reference, the specific contents are as follows

Using System; 
Using System.Collections.Generic; 
Using System.Linq; 
Using System.Text; 
Using System.Net.Security; 
Using System.Security.Cryptography.X509Certificates; 
Using System.Net; 
Using System.IO; 
Using System.IO.Compression; 
Using System.Text.RegularExpressions;
Using System.Security.Cryptography;
Using System.Web; public class Test {private static readonly string defaultuseragent = "mozilla/4.0" (compatible; MSIE 6.0; Windows NT 5.2; 
 
    SV1. NET CLR 1.1.4322;. NET CLR 2.0.50727) "; private static bool CheckValidationResult (object sender, X509Certificate certificate, X509chain chain, sslpolicyerrors Errors) {return true;///Always accept} static void Main (string[] args) {DateTime dt = Datetim 
      E.now; String mttime = dt.
      ToString ("Yyyymmddhhmmss");
   String pwd1 = "*************" +mttime; string pwd = GetMD5 (pwd1) string content = "read-letter" Authentication code 888888, you can't tell anyone about it!
      "; 
 String url = "Http://183.203.28.226:9000/HttpSmsMt";     Encoding Encoding = encoding.getencoding ("Utf-8"); 
      idictionary<string, string> parameters = new dictionary<string, string> (); Parameters. 
      ADD ("name", "* * *"); Parameters. 
      ADD ("pwd", PWD); Parameters.
      ADD ("content", content); Parameters.
      ADD ("Phone", "13381272353"); Parameters.
      ADD ("SubID", ""); Parameters. 
      ADD ("Mttime", mttime); 
      HttpWebResponse response = Createposthttpresponse (url,parameters,encoding); Print return value Stream stream = Response.  GetResponseStream (); Gets the string stream of the response StreamReader sr = new StreamReader (stream); Create a stream read Stream string html = Sr.  ReadToEnd ();  
    Read from the beginning to the end and place it in the string HTML Console.WriteLine (HTML);
      public static string GetMD5 (String myString) {MD5 MD5 = new MD5CryptoServiceProvider ();
      byte[] Fromdata = System.Web.HttpUtility.UrlEncode.GetBytes (myString);
      byte[] Fromdata = Encoding.Default.GetBytes (myString); byte[] Targetdata = Md5.computehash(Fromdata);
      string byte2string = null; for (int i=0;i<targetdata.length;i++) {byte2string+= targetdata[i].
      ToString ("X");
    return byte2string; public static HttpWebResponse createposthttpresponse (string url, idictionary<string, string> Parameters,enc 
      Oding charset) {HttpWebRequest request = null; HTTPSQ Request Servicepointmanager.servercertificatevalidationcallback = new Remotecertificatevalidationcallback (Check 
      Validationresult); 
      Request = WebRequest.Create (URL) as HttpWebRequest; Request. 
      ProtocolVersion = Httpversion.version10; Request. 
      method = "POST"; Request. 
      ContentType = "application/x-www-form-urlencoded"; Request. 
      useragent = defaultuseragent; If you need post data if (! Parameters = = NULL | | Parameters. 
        Count = = 0)) {StringBuilder buffer = new StringBuilder (); 
        int i = 0; foreach (string key in Parameters. 
Keys) {          if (i > 0) {buffer. 
          AppendFormat ("&{0}={1}", Key, Parameters[key]); else {buffer. 
          AppendFormat ("{0}={1}", Key, Parameters[key]); 
        } i++; } byte[] data = CharSet. GetBytes (buffer. 
        ToString ()); using (Stream stream = Request. GetRequestStream ()) {stream. Write (data, 0, data. 
        Length); } return request. 
    GetResponse () as HttpWebResponse; } 
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.