zoukankan      html  css  js  c++  java
  • 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)
                    {
                      
                    }
                }
                
            }
    
          
    
        }
    

      

  • 相关阅读:
    Java代理(jdk静态代理、动态代理和cglib动态代理)
    Hive安装
    Spark 集群安装
    Flume 远程写HDFS
    Spark Idea Maven 开发环境搭建
    oracle 通不过网络的原因
    oracle一些基本问题
    linux-redhat配置yum源
    liunx虚拟机网络连接
    redhat安装jdk、tomcat、mysql
  • 原文地址:https://www.cnblogs.com/lao-K/p/13684252.html
Copyright © 2011-2022 走看看