国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

HttpRequest Get和Post調用其他頁面的方法

2024-07-10 12:46:07
字體:
來源:轉載
供稿:網友

代碼如下:
  //Get請求方式
    private string RequestGet(string Url)
    {
        string PageStr = string.Empty;//用于存放還回的html
        Uri url = new Uri(Url);//Uri類 提供統一資源標識符 (URI) 的對象表示形式和對 URI 各部分的輕松訪問。就是處理url地址
        try
        {
            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);//根據url地址創建HTTpWebRequest對象
            #region 參數設置
            httprequest.Method = "get";

            //---------------------------------------------設定一些參數(不必要可以)
            //httprequest.KeepAlive = false;//持久連接設置為false
            //httprequest.ProtocolVersion = HttpVersion.Version11;// 網絡協議的版本
            //httprequest.Proxy = WebProxy.GetDefaultProxy();//服務器代理
            //httprequest.ContentType = "application/x-www-form-urlencoded";//http 頭
            //httprequest.AllowAutoRedirect = true;
            //httprequest.MaximumAutomaticRedirections = 10;
            //httprequest.Timeout = 30000;//設定超時十秒(毫秒)
            //httprequest.UserAgent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)"; //瀏覽器
            //=================================================
            #endregion
            HttpWebResponse response = (HttpWebResponse)httprequest.GetResponse();//使用HttpWebResponse獲取請求的還回值
            Stream steam = response.GetResponseStream();//從還回對象中獲取數據流
            StreamReader reader = new StreamReader(steam, Encoding.GetEncoding("gb2312"));//讀取數據Encoding.GetEncoding("gb2312")指編碼是gb2312,不讓中文會亂碼的
            PageStr = reader.ReadToEnd();
            reader.Close();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清苑县| 桑日县| 革吉县| 石景山区| 西和县| 大姚县| 福建省| 郴州市| 汾西县| 凤阳县| 通渭县| 靖州| 萝北县| 浦城县| 巢湖市| 伊金霍洛旗| 巧家县| 红原县| 开封县| 东光县| 恭城| 布拖县| 东山县| 青海省| 肥乡县| 鲜城| 启东市| 彰化市| 隆尧县| 杭锦后旗| 罗定市| 广元市| 河源市| 通城县| 广汉市| 尚义县| 康平县| 新丰县| 英吉沙县| 威海市| 巴东县|