简单GET
package mainimport ("fmt""io/ioutil""net/http")func main() {q, _ := http.Get("http://10.214.200.6:8080/")//打印状态码fmt.Println(q.Status)// 打印请求头fmt.Println(q.Header)//打印html源码html, _ := ioutil.ReadAll(q.Body)fmt.Println(string(html))}

自定义GET
很多时候,我们编写poc的时候,payload都是改变header的,需要自定义header。
package mainimport ("fmt""io/ioutil""net/http""time")func main() {//定义请求,但是不发送,只是定义u := "http://httpbin.org/get"q, _ := http.NewRequest("GET", u, nil)//自定义headerq.Header.Set("User-Agent", "ie")q.Header.Set("Oringin", "test.com")q.Header.Set("aaa", "aaa")//定义超时时间,也可以留空c := http.Client{Timeout: 3 * time.Second}//获取headerfmt.Println(q.Header)//发送请求re, _ := c.Do(q)//获取htmlhtml, _ := ioutil.ReadAll(re.Body)fmt.Println(string(html))}

简单POST
package mainimport ("net/http""strings")func main() {u := "http://10.214.200.6:8080/"http.Post(u, "application/x-www-foem-urlencoded", strings.NewReader("a = bb"))}
package mainimport ("net/http""net/url")func main() {u := "http://10.214.200.6:8080/"req := url.Values{}req.Set("a", "bb")http.PostForm(u, req)}
自定义POST
package mainimport ("bytes""encoding/json""fmt""net/http")func main() {u := "http://10.214.200.6:8080/"payload := map[string]string{"user": "admin","passwd": "admin",}buf, _ := json.Marshal(payload) //序列化成byte//新建请求,不发送req, _ := http.NewRequest("POST", u, bytes.NewReader(buf))//自定义headerreq.Header.Set("User-Agent", "ie")req.Header.Set("Cookie", "remenberme=1")//发送请求c := http.Client{}c.Do(req)fmt.Println(req.Header)}
忽略证书
在初始化客户端的时候忽略就可以了。
package mainimport ("bytes""crypto/tls""encoding/json""fmt""net/http")func main() {u := "https://www.baidu.com"payload := map[string]string{"user": "admin","passwd": "admin",}buf, _ := json.Marshal(payload) //序列化成byte//新建请求,不发送req, _ := http.NewRequest("POST", u, bytes.NewReader(buf))//自定义headerreq.Header.Set("User-Agent", "ie")req.Header.Set("Cookie", "remenberme=1")//初始化客户端,并发送请求//忽略证书nocert := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true},}c := http.Client{Transport: nocert}c.Do(req)fmt.Println(req.Header)}
