<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Go-RequestHTTP 客戶端請求包

          聯(lián)合創(chuàng)作 · 2023-09-29 08:39

          Go-Request 是 HTTP 客戶端請求包,靈感來源于 Python Requests。

          安裝

          go get -u github.com/mozillazg/request
          

          文檔

          API 文檔:https://godoc.org/github.com/mozillazg/request

          使用

          import (
              "github.com/mozillazg/request"
          )

          GET:

          c := new(http.Client)
          req := request.NewRequest(c)
          resp, err := req.Get("http://httpbin.org/get")
          j, err := resp.Json()
          defer resp.Body.Close()  // Don't forget close the response body

          POST:

          req.Data = map[string]string{
              "key": "value",
              "a":   "123",
          }
          resp, err := req.Post("http://httpbin.org/post")

          Cookies:

          req.Cookies = map[string]string{
              "key": "value",
              "a":   "123",
          }
          resp, err := req.Get("http://httpbin.org/cookies")

          Headers:

          req.Headers = map[string]string{
              "Accept-Encoding": "gzip,deflate,sdch",
              "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
          }
          resp, err := req.Get("http://httpbin.org/get")

          Files:

          f, err := os.Open("test.txt")
          req.Files = []request.FileField{
              request.FileField{"file", "test.txt", f},
          }resp, err := req.Post("http://httpbin.org/post")

          Json:

          req.Json = map[string]string{    "a": "A",    "b": "B",
          }resp, err := req.Post("http://httpbin.org/post")
          req.Json = []int{1, 2, 3}
          resp, err = req.Post("http://httpbin.org/post")

          Proxy:

          req.Proxy = "http://127.0.0.1:8080"
          // req.Proxy = "https://127.0.0.1:8080"
          // req.Proxy = "socks5://127.0.0.1:57341"
          resp, err := req.Get("http://httpbin.org/get")

          or https://github.com/mozillazg/request/tree/develop/_example/proxy

          HTTP Basic Authentication:

          req.BasicAuth = request.BasicAuth{"user", "passwd"}
          resp, err := req.Get("http://httpbin.org/basic-auth/user/passwd")

           

          瀏覽 17
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产小穴 | 中文字幕在线不卡 | 中文字幕在线播放亚洲 | 大香蕉在线视频11 | 精品91 |