zoukankan      html  css  js  c++  java
  • c#发送http请求

    直接代码,自己备用

        /**
             * @method:生成验证码
             */
            [JSONMethod]
            [Description ( "生成验证码" )]
            [DomTemplate ( )]
            public object GenerateVerify(IDictionary condition)
            {
                string username = "myname";
                string password = "mypass";
                string phone = "13566655555";
            string content = "";
    string vercode = ""; //generate verifyCode here Random random = new Random(); for (int i = 0; i < 6; i++) { int n = (int)(random.Next(0, 10)); vercode += n; } IDictionary cond = new Dictionary<string,string>(); cond.Add("vercode", vercode); //--------------------------------------------- content += "【魔兽科技】欢迎您注册魔兽网,您此次注册验证码是:"+vercode+",千万不要告诉别人哦!"; System.Net.WebRequest request = System.Net.WebRequest.Create("http://www.tosms.cn/Api/SendSms.ashx"); request.Method = "POST"; string postData = "username="+username+"&password="+password+"&phones="+phone+"&content="+content; byte[] byteArray = System.Text.Encoding.UTF8.GetBytes (postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; System.IO.Stream dataStream = request.GetRequestStream (); // Write the data to the request stream. dataStream.Write (byteArray, 0, byteArray.Length); dataStream.Close (); WebResponse response = request.GetResponse (); Console.WriteLine (((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream (); System.IO.StreamReader reader = new System.IO.StreamReader (dataStream); // Read the response status,wish:"1"==成功 string responseFromServer = reader.ReadToEnd (); reader.Close (); dataStream.Close (); response.Close (); return cond; }
  • 相关阅读:
    Postman 接口数据生成
    python中获取中位数(搬来的)
    数据库域名配置
    每10秒执行定时任务/每5分钟执行一次(附crontab的常用的命令)
    MATCHED 用法
    leetcode279 Perfect Squares
    leetcode480 Sliding Window Median
    leetcode295 Find Median from Data Stream
    leetcode424 Longest Repeating Character Replacement
    leetcode209 Minimum Size Subarray Sum
  • 原文地址:https://www.cnblogs.com/xiaoliu66007/p/4973385.html
Copyright © 2011-2022 走看看