首页 > Web开发 > 详细

调用接口并获取放回json值

时间:2015-08-17 15:27:30      阅读:175      评论:0      收藏:0      [点我收藏+]

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();
}
}

调用接口并获取放回json值

原文:http://www.cnblogs.com/zylong/p/4736674.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!