1、http的基本请求
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"net/url"
)
func post(){
r, err := http.Post("http://httpbin.org/post", "", nil)
if err != nil {
fmt.Println("ss")
}
defer r.Body.Close()
content, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println("ss")
}
fmt.Printf("%s", content)
}
func get(){
r, err := http.Get("http://httpbin.org/get")
if err != nil {
fmt.Println("ss")
}
defer r.Body.Close()
content, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println("ss")
}
fmt.Printf("%s", content)
}
//http只提供了get和post的基本请求,其他的情况不存在,因此,需要自己发起请求,构造方法
func put(){
requst, err := http.NewRequest(http.MethodPut, "http://httpbin.org/put", nil)
if err != nil {
fmt.Println("ss")
}
r, err := http.DefaultClient.Do(requst)
if err != nil {
fmt.Println("ss")
}
defer r.Body.Close()
content, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println("ss")
}
fmt.Printf("%s", content)
}
func deletets(){
requst, err := http.NewRequest(http.MethodDelete, "http://httpbin.org/delete", nil)
if err != nil {
fmt.Println("ss")
}
r, err := http.DefaultClient.Do(requst)
if err != nil {
fmt.Println("ss")
}
defer r.Body.Close()
content, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println("ss")
}
fmt.Printf("%s", content)
}
其中地址http://httpbin.org 是国外提供的一个验证http请求的网址,可以通过该网站进行测试。

![[动态规划] (八) LeetCode 931.下降路径最小和](https://img-blog.csdnimg.cn/img_convert/95457a156e1975d19c468325612a5ba4.png)
















![[动态规划] (七) 路径问题:LCR 166.剑指offer 47. 珠宝的最高价值](https://img-blog.csdnimg.cn/img_convert/5dfc9ff7d9bd1eb623c8db2f7f032a58.png)

