• get post请求 github.com/levigross/grequests

    r, _ := grequests.Get("http://www.baidu.com", nil)
      //fmt.Println(r.String())
      r.DownloadToFile("1.html")
    
      ro := &grequests.RequestOptions{Params: map[string]string{"Hello": "Goodbye"}}
      r1, _ := grequests.Get("http://httpbin.org/get?Hello=World", ro)
      fmt.Println(r1.String())
      resp, _ := grequests.Post("http://httpbin.org/post",
          &grequests.RequestOptions{Data: map[string]string{"One": "Two"}})
    
      if resp.Ok != true {
          log.Println("Request did not return OK")
      }
      fd, _ := grequests.FileUploadFromDisk("test_files/mypassword")
      resp1, _ := grequests.Post("http://httpbin.org/post",
          &grequests.RequestOptions{
              Files: fd,
              Data:  map[string]string{"One": "Two"},
          })
      if resp1.Ok != true {
          log.Println("Request did not return OK")
      }
      resp2, _ := grequests.Post("http://httpbin.org/post",
          &grequests.RequestOptions{
              JSON:   map[string]string{"One": "Two"},
              IsAjax: true,
          })
      if resp2.Ok != true {
          log.Println("Request did not return OK")
      }
      resp3, _ := grequests.Get("https://www.pcwebshop.co.uk/", &grequests.RequestOptions{InsecureSkipVerify: true})
      fmt.Println(resp3.String())
      ro1 := &grequests.RequestOptions{Auth: []string{"Levi", "Bot"}}
      resp4, _ := grequests.Get("http://httpbin.org/get", ro1)
      fmt.Println(resp4.Ok)
      session := grequests.NewSession(nil)
      resp5, _ := session.Get("http://httpbin.org/cookies/set", &grequests.RequestOptions{Params: map[string]string{"one": "two"}})
      fmt.Println(resp5.String())
      resp6, _ := grequests.Get("http://httpbin.org/cookies",
          &grequests.RequestOptions{
              Cookies: []*http.Cookie{
                  {
                      Name:     "TestCookie",
                      Value:    "Random Value",
                      HttpOnly: true,
                      Secure:   false,
                  }, {
                      Name:     "AnotherCookie",
                      Value:    "Some Value",
                      HttpOnly: true,
                      Secure:   false,
                  },
              },
          })
      fmt.Println(resp6.String())
      proxyURL, _ := url.Parse("http://127.0.0.1:8080") // Proxy URL
      resp7, _ := grequests.Get("http://www.levigross.com/",
          &grequests.RequestOptions{Proxies: map[string]*url.URL{proxyURL.Scheme: proxyURL}})
      fmt.Println(resp7.String())
  • 官方

    r, _ := http.Get("https://hellowindows.cn/")
      body, _ := io.ReadAll(r.Body)
      defer r.Body.Close()
      fmt.Println(string(body))
文档更新时间: 2024-10-19 18:22   作者:Yoby