<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 發起GET請求 > func NewRequest(method,urlStr,body ioReader) (*Request error) > method,請求方法,如GET > urlStr,請求url > body,參數,get請求傳空(nil) > ``` package main import ( "fmt" "io/ioutil" "net/http" //net/http來請求,io/ioutil來解析 ) func main() { // 創建一個客戶端對象client client := &http.Client{} // 創建一個請求對象 request request, err := http.NewRequest("GET", "http://www.baidu.com", nil) if err != nil { fmt.Println(err) } // client客戶端 調用do方法 發起請求 response接收數據 response, err := client.Do(request) // 輸出 響應體里面的狀態碼 200 fmt.Println(response.Body) // 解析response.Body數據 res, err := ioutil.ReadAll(response.Body) if err != nil { fmt.Println(err) } // 響應內容 body fmt.Println(string(res)) } ``` ### 使用Cookie,模擬用戶登錄 ``` package main import ( "fmt" "net/http" "strconv" ) func main() { // 創建一個請求客戶端 client := &http.Client{} request, err := http.NewRequest("GET", "http://www.baidu.com", nil) if err != nil { fmt.Println(err) } // 使用http.Cookie結構體初始化一個cookie鍵值對 cookie := &http.Cookie{Name: "userId", Value: strconv.Itoa(123456)} // 使用前面構造的request方法AddCookie往請求中添加Cookie request.AddCookie(cookie) request.AddCookie(&http.Cookie{Name: "session", Value: "ajkhkjgh="}) // client客戶端 調用do方法 發起請求 response接收數據 response, err := client.Do(request) // 打印設置的 cookie fmt.Println(response.Request.Cookies()) } ``` ### 設置請求頭 Header ``` package main import ( "fmt" "net/http" ) func main() { // 創建客戶端對象 client := &http.Client{} request, err := http.NewRequest("GET", "http://www.baidu.com/", nil) if err != nil { fmt.Println(err) } // 設置request的請求頭 Header request.Header.Set("Accept", "application/") //client客戶端 調用do方法 發起請求 response接收數據 response, err := client.Do(request) // 獲取響應頭 取出響應頭里面的 Content-Type //fmt.Println(response.Header) fmt.Println(response.Header.Get("Content-Type")) // 獲取請求頭 fmt.Println(response.Request.Header) } ``` ### 使用http包中的get請求方法 > func Get(url string) (resp *Response, err error) ``` package main import ( "fmt" "io/ioutil" "net/http" ) func main() { // http.Get()其實就是DefaultClient.Get(url) // 對于一般的http Request 可以使用,但是不能定制Request response, err := http.Get("http://www.baidu.com") if err != nil { fmt.Println(err) } defer response.Body.Close() // 打印響應頭 fmt.Println(response.Header) // 打印body body, err := ioutil.ReadAll(response.Body) fmt.Println(string(body)) } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看