C# 请求数据 方式1

 

 

 

public static string PostWebRequest2()
        {
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://183.66.231.18:8184/api/services/app/ChildSystem/checkLogin");//这是你要提交的url
            Encoding encoding = Encoding.UTF8;

            IDictionary<string, string> para = new Dictionary<string, string>();
            para.Add("ticket", "22d0a6a46bbdf44ec718f600b012b261");
          
            StringBuilder buffer = new StringBuilder();//这是要提交的数据
            int i = 0;

            foreach (string key in para.Keys)
            {
                if (i > 0)
                {
                    buffer.AppendFormat("&{0}={1}", key, para[key]);
                }
                else
                {
                    buffer.AppendFormat("{0}={1}", key, para[key]);
                }
                i++;
            }

            byte[] bs = Encoding.UTF8.GetBytes(buffer.ToString());//UTF-8
            string responseData = String.Empty;
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
            req.ContentLength = bs.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
            }
            using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
                {
                    responseData = reader.ReadToEnd().ToString();
                    return responseData;
                }
            }
        }

 

对应的 Postman 界面

C# 请求数据 方式1

 

C# 请求数据 方式1

上一篇:robotframework - selenium Api介绍


下一篇:在调用self对象时,本类调用用Win32Info().collect()