dongwen5336 2019-04-28 11:03
浏览 107

如何在Golang中修复“ net / http set header ORIGIN”

I built a small piece of code with the function of getting information from a website, and looks like it can't set orgin, because with curl in php, I was able to get the data with http status of 200. then I get 403. Hope everyone helps. Thank you very much

req, err:= http.NewRequest("GET", "https://immortal.hydrax.net/0/BRlsM329RNjbSqlWnRF36A4Kf5jx6qlZmoeLnJRi9A6b", nil)
    if err != nil {
        log.Fatal(err)
    }

    req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
    req.Header.Set("Origin", "https://hydrax.net")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()
    fmt.Printf("%s", resp.Status)

Output : 403 Forbiddenexit

  • 写回答

1条回答 默认 最新

  • donglanche9257 2019-04-28 12:04
    关注

    No sense to set origin because it's can't be modified programmatically. Probably your user agent header is not correct. Try this

        req.Header.Set("User-Agent", `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11`)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?