C# WebClient 发送post请求带参数

C# WebClient 发送post请求带参数

string param= "参数1";
string param2= "参数2";
string[,] sensorNumList = new string[3,5] {
            { "0011", "0012", "0013", "0014", "0015"},
            { "0016", "0017", "0018", "0019", "001a"},
            { "001b", "001c", "001d", "001e", "001f"}
            };//二维数组参数
string url = ""; // api路径(请求接口)
string paramList = "{\"param1\":" + param+ ",\"param2\":\"" + param2+ "\,\"sensorNumList \":\"" + sensorNumList + "\"}";
                byte[] postData = Encoding.UTF8.GetBytes(paramList );
                WebClient webClient = new WebClient();
                webClient .Headers.Add("Content-Type", "application/json"); //采取POST方式必须加的header
                webClient .Headers.Add("ContentLength", postData.Length.ToString());
                byte[] responseData = client.UploadData(url, "POST", postData); //得到返回字符流
                Encoding.UTF8.GetString(responseData); //解码

你可能感兴趣的:(C# WebClient 发送post请求带参数)