首页 > Windows开发 > 详细

c#的httpWebRequest(2)

时间:2018-01-03 18:22:09      阅读:264      评论:0      收藏:0      [点我收藏+]

public string httpWebservice(string url, string body)
        {
            string rootUrl = ConfigHelper.AppSettings("RemoteHttpURL");
            WebRequest wRequest = WebRequest.Create(rootUrl + url);
            wRequest.Method = "POST";
            wRequest.Timeout = 20000;
            wRequest.ContentType = "application/x-www-form-urlencoded";

            byte[] btBodys = Encoding.UTF8.GetBytes(body);
            wRequest.ContentLength = btBodys.Length;
            wRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);

            WebResponse wResponse = wRequest.GetResponse();
            Stream stream = wResponse.GetResponseStream();
            StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
            string str = reader.ReadToEnd();   //url返回的值  
            reader.Close();
            wResponse.Close();
            return str;
        }

c#的httpWebRequest(2)

原文:https://www.cnblogs.com/tianxinrj/p/8184950.html

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