resp, err := http.Get("http://example.com/")
...
//参数 详解
//1. 请求的目标 URL
//2. 将要 POST 数据的资源类型(MIMEType)
//3. 数据的比特流([]byte形式)
resp, err := http.Post("http://example.com/upload", "image/jpeg", &buf)
...
//参数 详解
//1. 请求的目标 URL
//2. 提交的参数值 可以使用 url.Values 或者 使用 strings.NewReader("key=value&id=123")
// 注意,也可以 url.Value 和 strings.NewReader 并用 strings.NewReader(url.Values{}.Encode())
resp, err := http.PostForm("http://example.com/form",
url.Values{"key": {"Value"}, "id": {"123"}})
resp, err := http.Get("http://example.com/")
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
resp, err := http.Post("http://example.com/upload", "image/jpeg", &buf)
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
postValue := url.Values{
"email": {"xx@xx.com"},
"password": {"123456"},
}
resp, err := http.PostForm("http://example.com/login", postValue)
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
postValue := url.Values{
"email": {"xx@xx.com"},
"password": {"123456"},
}
postString := postValue.Encode()
req, err := http.NewRequest("POST","http://example.com/login_ajax", strings.NewReader(postString))
if err != nil {
// handle error
}
// 表单方式(必须)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
//AJAX 方式请求
req.Header.Add("x-requested-with", "XMLHttpRequest")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
// handle error
}
fmt.Println(string(body))
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有