Beego Httplib 设置代理

Jackey Golang 4,537 次浏览 , 没有评论
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "github.com/astaxie/beego/httplib"
  6. "net/http"
  7. "net/url"
  8. "time"
  9. )
  10.  
  11. func main() {
  12. content := "提交内容"
  13. req := httplib.Post("https://www.baidu.com").SetProxy(func(request *http.Request) (*url.URL, error) {
  14. u := new(url.URL)
  15. u.Scheme = "http" // 代理协议
  16. u.Host = "127.0.0.1:49389" // 代理IP 及端口
  17. return u, nil
  18. })
  19. req.SetTimeout(500*time.Millisecond, 500*time.Microsecond) //设置超时时间
  20. req.Body(content)
  21. result, _ := req.String()
  22. fmt.Println(result)
  23. }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Go