zoukankan      html  css  js  c++  java
  • HttpWebRequest提交数据

    private string WebRequestMethod(string RequestUrl)
        {
            string str = "";
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            StreamReader reader = null;
            try
            {
                
                request = (HttpWebRequest) WebRequest.Create(RequestUrl);
                request.CookieContainer = this.Cookie;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24";
                response = (HttpWebResponse) request.GetResponse();
                reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                str = reader.ReadToEnd();
                reader.Close();
                response.Close();
            }
            catch (Exception exception)
            { 
                return "";
            }
            return str.Trim();
        }
    
        private string RequestPostMethod(string Post_Url, string PostData)
        {
            string str = "";
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            StreamReader reader = null;
            byte[] bytes = new ASCIIEncoding().GetBytes(PostData);
            try
            {
                request = (HttpWebRequest) WebRequest.Create(Post_Url);
                request.CookieContainer = this.Cookie;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24";
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = bytes.Length;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Flush();
                requestStream.Close();
                response = (HttpWebResponse) request.GetResponse();
                reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                str = reader.ReadToEnd();
                reader.Close();
                response.Close();
            }
            catch (Exception exception)
            {
                return "";
            }
            return str.Trim();
        }
  • 相关阅读:
    Flutter-常用插件庫
    Flutter-發送短信驗證碼
    Flutter-Radio單選框
    Flater-Provide狀態管理
    android sdk安装
    Android Studio的安装
    Flutter SDK安装(windows)
    Flutter-dialog彈出框
    python中的迭代器与生成器
    python闭包与装饰器
  • 原文地址:https://www.cnblogs.com/ericyuan/p/3242850.html
Copyright © 2011-2022 走看看