求教URL发送JSON格式数据问题
2个回答
展开全部
数据的话,直接“&参数名 =参数值”的形式即可,主要是文件流需要进行相应的定义,举例:以文件流的方式发送 和接收。
postData += ("&hashcode=" + GetMD5String(pwd));
byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("url");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";//定义文件流形式,这个就是流的类型。
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
// 接收
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
postData += ("&hashcode=" + GetMD5String(pwd));
byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("url");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";//定义文件流形式,这个就是流的类型。
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
// 接收
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询