golang http 请求封装
简介
实现http请求
使用
go get github.com/wms3001/http
实例
- get
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token", //url
"", // username
"", //password
m, //header
a, //accept
"", //body
10, //timeout
"", //type
[]byte{}, //file
}
resp := hp.Get()
- post
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Post()
- delete
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Delete()
- head
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Head()
- options
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Options()
- put
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Put()
- trace
m := map[string]string{
"name": "backy",
"species": "dog",
}
a := map[string]string{
"Accept": "application/json",
//"Accept": "text/plain",
}
hp := Http{
"https://www.wishpost.cn/api/v3/oauth/access_token",
"",
"",
m,
a,
"",
10,
"",
[]byte{},
}
resp := hp.Trace()