0

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

2
  • 1
    It looks like that's a forbidden header name so you won't be able to set it programmatically. Commented Apr 28, 2019 at 11:09
  • Hi. Thanks for your answer, can you help me with a solution to this problem? because I see the orgin curl still works Commented Apr 28, 2019 at 11:15

1 Answer 1

1

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`)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks , it worked. My code: is ` 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") ` and it doesn't work. Your work has been active. Thanks for helping me. Thanks very much
Glad I could help ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.