WEBAPI POST 传递多个参数时使用dynamic

WEBAPI POST 传递多个参数时使用dynamic

 

 

 [HttpPost]
        // POST: api/EasyModelByRequestUrl
        public string Post(dynamic student)
        {


            return $"Post请求 姓名{student.name},性别{student.sex},年龄{student.age}";
        }

  

var student = new {name="张老三",sex="雄性",age=29 };


            Byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(student));
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:9892/api/EasyModelByRequestUrl");
            request.Method = "POST";

            request.ContentType = "application/json;charset=utf-8";
            request.ContentLength = bytes.Length;




            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader reader=new StreamReader( response.GetResponseStream()))
            {
                string result=reader.ReadToEnd();
                this.textBox1.Text = result;
            }

  

上一篇:【Python强化】使用pandas和csv读取csv文件


下一篇:预备知识-python核心用法常用数据分析库(下)