真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

HttpRequestGet和Post怎么調(diào)用其他頁(yè)面-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“HttpRequest Get和Post怎么調(diào)用其他頁(yè)面”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)公司提供成都網(wǎng)站制作、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì),高端網(wǎng)站設(shè)計(jì),廣告投放平臺(tái)等致力于企業(yè)網(wǎng)站建設(shè)與公司網(wǎng)站制作,十余年的網(wǎng)站開(kāi)發(fā)和建站經(jīng)驗(yàn),助力企業(yè)信息化建設(shè),成功案例突破成百上千,是您實(shí)現(xiàn)網(wǎng)站建設(shè)的好選擇.

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


  //Get請(qǐng)求方式
    private string RequestGet(string Url)
    {
        string PageStr = string.Empty;//用于存放還回的html
        Uri url = new Uri(Url);//Uri類 提供統(tǒng)一資源標(biāo)識(shí)符 (URI) 的對(duì)象表示形式和對(duì) URI 各部分的輕松訪問(wèn)。就是處理url地址
        try
        {
            HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);//根據(jù)url地址創(chuàng)建HTTpWebRequest對(duì)象
            #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è)定超時(shí)十秒(毫秒)
            //httprequest.UserAgent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)"; //瀏覽器
            //=================================================
            #endregion
            HttpWebResponse response = (HttpWebResponse)httprequest.GetResponse();//使用HttpWebResponse獲取請(qǐng)求的還回值
            Stream steam = response.GetResponseStream();//從還回對(duì)象中獲取數(shù)據(jù)流
            StreamReader reader = new StreamReader(steam, Encoding.GetEncoding("gb2312"));//讀取數(shù)據(jù)Encoding.GetEncoding("gb2312")指編碼是gb2312,不讓中文會(huì)亂碼的
            PageStr = reader.ReadToEnd();
            reader.Close();
        }
        catch (Exception e)
        {
            PageStr += e.Message;
        }
        return PageStr;
    }

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


//Post請(qǐng)求方式,于Get的方式寫(xiě)法相似,所以解釋就些少一點(diǎn)了

  private string RequestPost(string Url,string Context)//兩個(gè)參數(shù)分別是Url地址和Post過(guò)去的數(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;
        }


“HttpRequest Get和Post怎么調(diào)用其他頁(yè)面”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!


分享文章:HttpRequestGet和Post怎么調(diào)用其他頁(yè)面-創(chuàng)新互聯(lián)
新聞來(lái)源:http://weahome.cn/article/djdoos.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部