PHP
·
发表于 5年以前
·
阅读量:8282
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"encoding/json"
)
func main() { //生成client 参数为默认
client := &http.Client{}
//生成要访问的url
url := "http://somesite/somepath/"
//提交请求
reqest, err := http.NewRequest("GET", url, nil)
//增加header选项
reqest.Header.Add("Cookie", "xxxxxx")
reqest.Header.Add("User-Agent", "xxx")
reqest.Header.Add("X-Requested-With", "xxxx")
if err != nil {
panic(err)
}
//处理返回结果
response, _ := client.Do(reqest)
defer response.Body.Close()
// ...
}