VB.net 2010 视频教程 VB.net 2010 视频教程 VB.net 2010 视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > C#编程 >
  • C#教程之C#使用post方式提交json数据

  • 2019-07-18 23:01 来源:未知

尝试了一天,尝试了各种方法,一下方法最直接方便. 

复制代码
//地址
            string _url = "https://www.dXXXayup.ink/api/User/Login";
            //json参数
            string jsonParam = "{ phonenumber:\"18665885202\",pwd:\"tsp\"}";
            var request = (HttpWebRequest)WebRequest.Create(_url);
            request.Method = "POST";
            request.ContentType = "application/json;charset=UTF-8";
            byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
            int length = byteData.Length;
            request.ContentLength = length;
            Stream writer = request.GetRequestStream();
            writer.Write(byteData, 0, length);
            writer.Close();
            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
            MessageBox.Show(responseString.ToString());
 

相关教程