# README
封装golang http请求
设置host发送请求
...
client := NewClient(WithHost("http://localhost"))
response, err := client.Get("/api/test")
if err != nil {
return err
}
fmt.Println(response.String())
data := map[string]interface{}
err = response.JSON(data)
if err != nil {
return err
}
...
不设置host发送请求
...
client := NewClient()
response, err := client.Get("http://localhost/api/test")
if err != nil {
return err
}
fmt.Println(response.String())
data := map[string]interface{}
err = response.JSON(data)
if err != nil {
return err
}
...
设置query请求
...
client := NewClient()
response, err := client.RequestQuery(map[string][]string{
"id": {"1", "2", "3"},
"name": {"zhangsan"},
}).Get("/api/test")
if err != nil {
return err
}
fmt.Println(response.String())
data := map[string]interface{}
err = response.JSON(data)
if err != nil {
return err
}
...
设置Json请求体
...
client := NewClient()
response, err := client.RequestJSON(map[string]interface{}{
"id": "1",
"name": "zhangsan",
}).Post("/api/test")
if err != nil {
return err
}
fmt.Println(response.String())
data := map[string]interface{}
err = response.JSON(data)
if err != nil {
return err
}
...
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
设置请求头.
设置超时时间.
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author