package controllers
import (
"fmt"
"github.com/astaxie/beego"
"io/ioutil"
"net/http"
)
type MainController struct {
beego.Controller
}
func (c *MainController) Get() {
c.TplNames = "index.html"
}
func (this *MainController) Test() {
//注释取消要需引入包net/url 通过设置代理请求下载页面
//url, _ := url.Parse("172.17.184.82")
//proxy := http.ProxyURL(url)
//client := &http.Client{
// Transport: &http.Transport{
// Proxy: proxy,
// },
//}
resp, err := http.Get("http://www.baidu.com/")
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
this.Ctx.WriteString(string(body))
}
[GO]HTTP 请求实例(GET)以及设置代理
最新推荐文章于 2024-08-30 07:58:22 发布