校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > HttpRequest Get和Post調(diào)用其他頁面的方法

HttpRequest Get和Post調(diào)用其他頁面的方法

熱門標(biāo)簽:廈門四川外呼系統(tǒng) 怎樣在地圖標(biāo)注消火栓圖形 百度地圖標(biāo)注點擊事件 泰州手機外呼系統(tǒng)軟件 杭州智能電話機器人 內(nèi)蒙古智能電銷機器人哪家強 地圖標(biāo)注位置多的錢 濟源人工智能電話機器人價格 山東防封電銷卡辦理套餐

復(fù)制代碼 代碼如下:

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

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

復(fù)制代碼 代碼如下:

//Post請求方式,于Get的方式寫法相似,所以解釋就些少一點了
 

  private string RequestPost(string Url,string Context)//兩個參數(shù)分別是Url地址和Post過去的數(shù)據(jù)
    {
        string PageStr=string.Empty;
        Uri url = new Uri(Url);
        byte[] reqbytes=Encoding.ASCII.GetBytes(Context);
        try
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "post";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = reqbytes.Length;
            Stream stm = req.GetRequestStream();
            stm.Write(reqbytes, 0, reqbytes.Length);

            stm.Close();
            HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
            Stream stream = wr.GetResponseStream();
            StreamReader srd= new StreamReader(stream,Encoding.GetEncoding("gb2312"));
            PageStr += srd.ReadToEnd();
            stream.Close();
            srd.Close();
        }
        catch (Exception e)
        {
            PageStr += e.Message;
        }
        return PageStr;
    }

復(fù)制代碼 代碼如下:

public string WebClientGet(string url)
        {
            var client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            var stream = client.OpenRead(url);
            if (stream == null) return "";
            var reader = new StreamReader(stream, Encoding.Default);
            var result = reader.ReadToEnd();
            stream.Close();
            reader.Close();
            return result;
        }

標(biāo)簽:臺州 洛陽 周口 朔州 百色 朝陽 新鄉(xiāng) 喀什

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HttpRequest Get和Post調(diào)用其他頁面的方法》,本文關(guān)鍵詞  HttpRequest,Get,和,Post,調(diào)用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HttpRequest Get和Post調(diào)用其他頁面的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于HttpRequest Get和Post調(diào)用其他頁面的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 苗栗县| 蚌埠市| 彰化市| 房产| 大埔县| 武义县| 澄城县| 合水县| 永胜县| 彭水| 岳池县| 涟源市| 西峡县| 福海县| 宁陵县| 巩义市| 汉阴县| 楚雄市| 三河市| 徐闻县| 宿州市| 高唐县| 扶风县| 冀州市| 呼图壁县| 兰坪| 南安市| 安图县| 岳普湖县| 甘谷县| 彭州市| 宁南县| 永修县| 九台市| 南华县| 昌平区| 平度市| 博乐市| 龙泉市| 南阳市| 剑河县|