首页 > Web开发 > 详细

POST请求——HttpWebRequest

时间:2017-11-21 13:40:58      阅读:155      评论:0      收藏:0      [点我收藏+]
string url="";
string param="";
string result = string.Empty;
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
Encoding encoding = Encoding.UTF8;
byte[] bs = Encoding.UTF8.GetBytes(param);
string responseData = String.Empty;
req.Method = "Post";
req.Accept = "application/json, text/javascript, */*; q=0.01";
req.ContentType = "application/json; charset=UTF-8";
using (Stream reqStream = req.GetRequestStream())
{
    reqStream.Write(bs, 0, bs.Length);
    reqStream.Close();
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
    {
        responseData = reader.ReadToEnd().ToString();
    }
    result = responseData;
}

POST请求——HttpWebRequest

原文:http://www.cnblogs.com/Lulus/p/7872354.html

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