我们在开发的过程中多多少少会要跟其他服务做交互,很多都是http请求,但是在go语言里面怎么样请求http请求,今天先讲比较初级的。示例如下:
GET
import (
"fmt"
"net/http"
"io/ioutil"
)
func main(){
response,err := ("")
if(err!=nil){
(err)
}
defer ()
body,err := ()
(string(body))
}
post
import (
"fmt"
"net/http"
"io/ioutil"
"strings"
)
func main(){
client := &{}
requst, err := ("POST",
"",
("name=abc"))
if err != nil {
return
}
("Content-Type", "application/x-www-form-urlencoded")
response, err := (requst)
if err != nil {
return
}
defer ()
body, err := ()
if err != nil {
return
}
(string(body))
}
推荐文档:/developer/section/1143633