码迷,mamicode.com
首页 > Windows程序 > 详细

c#的httpWebRequest(2)

时间:2018-01-03 18:37:57      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:end   ext   creat   class   set   toe   reader   ring   for   

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)

标签:end   ext   creat   class   set   toe   reader   ring   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!