如何在.net中模拟post方式提交json数据
1个回答
展开全部
c# 模拟post 提交
string postData = "user=123&pass=456"; // 要发放的数据
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://www.abc.com/a.aspx");
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebRequest.ContentLength = byteArray.Length;
Stream newStream = objWebRequest.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader sr=new StreamReader(response.GetResponseStream(), Encoding.Default);
string textResponse = sr.ReadToEnd(); // 返回的数据
string postData = "user=123&pass=456"; // 要发放的数据
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://www.abc.com/a.aspx");
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objWebRequest.ContentLength = byteArray.Length;
Stream newStream = objWebRequest.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader sr=new StreamReader(response.GetResponseStream(), Encoding.Default);
string textResponse = sr.ReadToEnd(); // 返回的数据
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询