zoukankan      html  css  js  c++  java
  • 获取http请求

        public  string GetUrlDate(string url, string method, string content)
        {
            string outstring = "";
            try
            {
                System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                myRequest.Method = method;
                myRequest.KeepAlive = false;
                myRequest.ContentType = "application/x-www-form-urlencoded";

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                string postData = content;
                byte[] data = encoding.GetBytes(postData);
                myRequest.ContentLength = data.Length;
                System.IO.Stream newStream = myRequest.GetRequestStream();
                newStream.Write(data, 0, data.Length);
                newStream.Close();


                using (System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse())
                {

                    System.IO.StreamReader sr = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                    outstring= sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                IExceptionPublisher Publisher = new ExceptionPublisher();
                Publisher.Publish(ex, null, null);
                outstring= "";
            }
            return outstring;
        }

  • 相关阅读:
    html meta标签使用总结
    HTTP与HTTPS握手的那些事
    JS windows.open打开窗口并居中
    什么是响应式web设计
    phpstorm2017 激活方法
    php与mysql 绑定变量和预定义处理
    php和mysql数据库防SQL注入的有效解决办法
    如何高效率的写一个不会重复出现的随机数
    php将IP地址转换为真实地址的方法
    PHP程序员要掌握哪些技术
  • 原文地址:https://www.cnblogs.com/linzheng/p/1814162.html
Copyright © 2011-2022 走看看