美文网首页
golang http 代理 这样就可以通过 fiddler抓包

golang http 代理 这样就可以通过 fiddler抓包

作者: 夏树的宝马 | 来源:发表于2021-10-01 19:13 被阅读0次
package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
    "os"
)

func main() {

    // 设置代理
    os.Setenv("HTTP_PROXY", "http://127.0.0.1:8899")
    os.Setenv("HTTPS_PROXY", "https://127.0.0.1:9743")
    c := http.Client{
        // Transport: &http.Transport{
        //  Proxy: http.ProxyURL(urlproxy),
        // },
    }
    reqest, _ := http.NewRequest("GET", "http://www.httpbin.org/",nil)

    resp,err:=c.Do(reqest)
    if err != nil {
        fmt.Println(err.Error())
    }
    defer c.CloseIdleConnections()
    //defer resp.Close
    body,_:=ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))

}

相关文章

网友评论

      本文标题:golang http 代理 这样就可以通过 fiddler抓包

      本文链接:https://www.haomeiwen.com/subject/iuzenltx.html