国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

使用C#發(fā)送HTTP的Get和Post請求

這篇具有很好參考價值的文章主要介紹了使用C#發(fā)送HTTP的Get和Post請求。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

c#使用HTTP發(fā)送GET()請求:

        public static string GetHttpResponse(string url, int Timeout)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";
            request.UserAgent = null;
            request.Timeout = Timeout;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

?c#使用HTTP發(fā)送POST()請求(不攜帶任何參數(shù)):

        public static string PostHttpResponse(string url,  int Timeout)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "text/html;charset=UTF-8";
            request.UserAgent = null;
            request.Timeout = Timeout;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

?c#使用HTTP發(fā)送POST()請求(請求參數(shù)攜帶在head):

public static string PostHttpResponseFromHead(string url, int Timeout,string parameter)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "text/html;charset=UTF-8";
            request.UserAgent = null;
            request.Timeout = Timeout;
            request.Headers.Add(parameter);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

?c#使用HTTP發(fā)送POST()請求(請求參數(shù)攜帶在body):

 public static string PostHttpResponseFromBody(string url, string body)
        {
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/json";
            byte[] buffer = encoding.GetBytes(body);
            request.ContentLength = buffer.Length;
            request.GetRequestStream().Write(buffer, 0, buffer.Length);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
            {
                return reader.ReadToEnd();
            }
        }

文章來源地址http://www.zghlxwxcb.cn/news/detail-724016.html

到了這里,關(guān)于使用C#發(fā)送HTTP的Get和Post請求的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • (一)python發(fā)送HTTP 請求的兩種方式(get和post )

    注:發(fā)送請求(包括請求行、方法類型、頭、體) 常見的請求方式有g(shù)et、post、put、delete ? ? ? ? ? ?格式:requests.get() (內(nèi)容: url必填; params選填:url參數(shù)字典) # ~ 無參數(shù)的get請求 # ~ 有參數(shù)的get請求 # ~ 使用params的get請求 ? ? ? ?知識擴展# ?requests.post() post請求分為5種,常用

    2024年02月02日
    瀏覽(38)
  • java業(yè)務(wù)代碼發(fā)送http請求(Post方式:請求參數(shù)為JSON格式;Get方式)

    實際開發(fā)中,可能需要發(fā)送http請求到第三方服務(wù)獲取數(shù)據(jù),于是就有以下應(yīng)用: 依賴: 假設(shè)我需要在我的業(yè)務(wù)代碼中調(diào)用該地址: url:http://xx.xx:xxxx/user/count 請求方法:post 內(nèi)容類型:application/json 請求參數(shù):id, username 返回參數(shù):code 響應(yīng)結(jié)果 int類型 ? ? ? ? ? ? ? ? ?

    2024年02月12日
    瀏覽(32)
  • C語言通過IXMLHTTPRequest以get或post方式發(fā)送http請求獲取服務(wù)器文本或xml數(shù)據(jù)

    C語言通過IXMLHTTPRequest以get或post方式發(fā)送http請求獲取服務(wù)器文本或xml數(shù)據(jù)

    做過網(wǎng)頁設(shè)計的人應(yīng)該都知道ajax。 Ajax即Asynchronous Javascript And XML(異步的JavaScript和XML)。使用Ajax的最大優(yōu)點,就是能在不更新整個頁面的前提下維護數(shù)據(jù)。這使得Web應(yīng)用程序更為迅捷地回應(yīng)用戶動作,并避免了在網(wǎng)絡(luò)上發(fā)送那些沒有改變的信息。 在IE瀏覽器中,Ajax技術(shù)就是

    2024年01月25日
    瀏覽(26)
  • 使用Go發(fā)送HTTP GET請求

    使用Go發(fā)送HTTP GET請求

    在Go語言中,我們可以使用 net/http 包來發(fā)送HTTP GET請求。以下是一個簡單的示例,展示了如何使用Go發(fā)送HTTP GET請求并獲取響應(yīng)。 go 復(fù)制代碼 package ?main import ?( \\\"fmt\\\" ? \\\"io/ioutil\\\" ? \\\"net/http\\\" ? ) func ? main () ?{ // 創(chuàng)建一個HTTP客戶端 client := http.Client{} // 創(chuàng)建一個GET請求 req, err :=

    2024年01月23日
    瀏覽(19)
  • HTTP請求:GET/POST請求

    HTTP請求:GET/POST請求

    GET? 用于:地址欄請求? 通過url請求 POST 用于:表單請求 DELETE 用于刪除 PUT 用于更新 GET的請求直接嵌入在路徑中URL是完整的請求路徑,包括了 ?后面的部分,因此你可以手動解析后面的內(nèi)容作為GET請求的參數(shù) node.js是UEL模塊中的parse函數(shù)提供了這個功能。 util是node.js常用工具

    2024年02月16日
    瀏覽(20)
  • uniapp發(fā)起post和get請求——this.$http.get 和 this.$http.post傳參

    main.js按照內(nèi)容自行修改

    2024年02月15日
    瀏覽(51)
  • 使用bash腳本在Linux中發(fā)送HTTP GET請求

    使用bash腳本在Linux中發(fā)送HTTP GET請求

    在Linux中,使用bash腳本發(fā)送HTTP GET請求是一種常見的自動化任務(wù)。下面是一個簡單的bash腳本示例,用于發(fā)送HTTP GET請求并處理響應(yīng): bash 復(fù)制代碼 #!/bin/bash # 定義URL url= \\\"http://example.com\\\" ? # 發(fā)送GET請求并獲取響應(yīng) response=$(curl -s \\\" $url \\\" ) # 檢查響應(yīng)狀態(tài)碼 if ?[ $? -eq 0 ]; then ? e

    2024年01月22日
    瀏覽(89)
  • HTTP中g(shù)et和post請求方式

    #get和post特點 get請求: 請求參數(shù)在請求地址后面,提交的數(shù)據(jù)量較小,安全性較差,不建議用來提交敏感信息(地址欄中會顯示,并且有可能被保存請求地址)。 功能:GET 方法用于獲取由 Request-URI 所標識的資源的信息 默認方法: GET方法是默認的HTTP請求方法 ,例如當我們

    2024年04月26日
    瀏覽(20)
  • QT進行http請求(post/get)

    在剛接觸QT時第一個任務(wù)就是進行http請求,現(xiàn)在才開始記錄,可能會有遺漏的點。 一、post請求 在.pro文件中 在.h文件中添加對應(yīng)的頭文件 在.cpp中 二、get請求 .pro和.h文件和post請求一樣,在.cpp中

    2024年02月11日
    瀏覽(21)
  • Http中post/get請求參數(shù)接收

    Http中post/get請求參數(shù)接收

    Http請求報文示例圖如下: ? ①是請求方法,GET和POST是最常見的HTTP方法,除此以外還包括DELETE、HEAD、OPTIONS、PUT、TRACE。不過,當前的大多數(shù)瀏覽器只支持GET和POST,Spring 3.0提供了一個HiddenHttpMethodFilter,允許通過_method的表單參數(shù)指定這些特殊的HTTP方法(實際上還是通過POST提

    2024年01月25日
    瀏覽(34)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包