调用接口并获取放回json值
public static string PostDataGetHtml(string uri, string postData)
{
try
{
byte[] data = Encoding.UTF8.GetBytes(postData);
Uri uRI = new Uri(uri);
HttpWebRequest req = WebRequest.Create(uRI) as HttpWebRequest;
req.Method = "POST";
req.KeepAlive = true;
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
req.AllowAutoRedirect = true;
Stream outStream = req.GetRequestStream();
outStream.Write(data, 0, data.Length);
outStream.Close();
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
Stream inStream = res.GetResponseStream();
StreamReader sr = new StreamReader(inStream, Encoding.UTF8);
string htmlResult = sr.ReadToEnd();
return htmlResult;
}
catch (Exception ex)
{
return "网络错误:" + ex.Message.ToString();
}
}