欢迎光临
我的个人博客网站

HttpWebRequest的个人见解

 class ITInfo_SFC     {         public bool bPingFaile = false;         HttpWebRequest http;         public Server server;         public string url = "https://www.baidu.com/";         public string SFC_ip = "127.0.0.1";                            public static bool OnLine()         {             //public string SFC_ip ="127.0.0.1";             Ping ping = new Ping();             PingReply pingReply = ping.Send("127.0.0.1");             if (pingReply.Status == IPStatus.Success)             {                 return true;             }             else                 return false;         }         public void InitURLValue(string url)         {             this.url = url;             http = WebRequest.CreateHttp(url) as HttpWebRequest;          }           public static string PostToUrl(string requestUrl, byte[] byteArrayPost, Encoding encoding)         {             if (OnLine())             {                 try                 {                     string stringResponse = "";                     HttpWebRequest webRequest = WebRequest.CreateHttp(url) as HttpWebRequest;                     webRequest.Method = "POST";                     webRequest.ContentType = "application/x-www-form-urlencoded";                     webRequest.ContentLength = byteArrayPost.Length;                     webRequest.CookieContainer = new CookieContainer();                     webRequest.Credentials = CredentialCache.DefaultCredentials;                      Stream newStream = webRequest.GetRequestStream();                     //写入参数                     newStream.Write(byteArrayPost, 0, byteArrayPost.Length);                     newStream.Close();                       WebResponse webResponse = webRequest.GetResponse();                     StreamReader responseStream = new StreamReader(webResponse.GetResponseStream(), encoding);                     stringResponse = responseStream.ReadToEnd();                     webResponse.Close();                     responseStream.Close();                     return stringResponse;                 }                 catch (Exception)                 {                                    }             }                      }              } 

  

赞(0) 打赏
未经允许不得转载:张拓的天空 » HttpWebRequest的个人见解
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

专业的IT技术经验分享 更专业 更方便

联系我们本站主机

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏