Golang:grequests库-一个类似Requests的http客户端

A Go “clone” of the great and famous Requests library

文档

安装依赖

go mod init requests-demo

go get -u github.com/levigross/grequests

代码示例

package main

import (
    "fmt"

    "github.com/levigross/grequests"
)

func main() {
    
    
    // 请求参数
    options := &grequests.RequestOptions{
    
    
        Params: map[string]string{
    
    
            "name": "Tom",
            "age":  "20",
        },
    }

    resp, _ := grequests.Get("http://httpbin.org/get", options)

    if resp.Ok {
    
    
        fmt.Println(resp.String())
    }

}

输出结果

{
    
    
  "args": {
    
    
    "age": "20", 
    "name": "Tom"
  }, 
  "headers": {
    
    
    "Accept-Encoding": "gzip", 
    "Host": "httpbin.org", 
    "User-Agent": "GRequests/0.10", 
    "X-Amzn-Trace-Id": "Root=1-64190bc5-1b1798e46aaffd4658f84da3"
  }, 
  "origin": "1.202.253.34", 
  "url": "http://httpbin.org/get?age=20&name=Tom"
}

其他同类库

猜你喜欢

转载自blog.csdn.net/mouday/article/details/129681989
今日推荐