怎样通过http调用web服务器的接口
展开全部
WebRequest request = WebRequest.Create(url);
request.Method = "Post";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
StreamWriter sw = new StreamWriter(request.GetRequestStream());
sw.Write(postData);
sw.Flush();
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"));
MessageBox.Show(sr.ReadToEnd());
sw.Dispose();
sw.Close();
sr.Dispose();
sr.Close();
s.Dispose();
s.Close();
request.Method = "Post";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
StreamWriter sw = new StreamWriter(request.GetRequestStream());
sw.Write(postData);
sw.Flush();
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"));
MessageBox.Show(sr.ReadToEnd());
sw.Dispose();
sw.Close();
sr.Dispose();
sr.Close();
s.Dispose();
s.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询