0

I am accessing a certain server in my organization's internal network from my browser fine. But when i try to make the same call from a Go code in Atom. it throws the below error.

url := "http://server:port/getcall"

req, _ := http.NewRequest("GET", url, nil)

res, _ := http.DefaultClient.Do(req)
<body><h1>DNS error</h1>
<p>DNS error (the host name of the page you are looking for does not exist)<br><br>
Please check that the host name has been spelled correctly.<br></p>    

what could it be ? i tried setting and removing proxies which isnt working.

Divya MV
  • 2,021
  • 3
  • 31
  • 55
  • Does your browser use a proxy while your go program does not? Are they both running on the same machine? What os are you using? – Fabian Jan 08 '21 at 14:20
  • yes browser does,and i have the same proxy used in my editor where the program is written. both are running on same machine.os is windows – Divya MV Jan 09 '21 at 03:51
  • 1
    Try this here: https://stackoverflow.com/questions/14661511/setting-up-proxy-for-http-client You should probably set HTTP_PROXY environment variable to the settings the browser uses. – Fabian Jan 09 '21 at 12:52
  • @Fabian.. thanks this did help resolve the issue. Thank you, have a good day! – Divya MV Jan 10 '21 at 04:45
  • @Fabian: it had worked once and later when i was trying again...i see that its throwing the DNS error again even when the init() has the proxy set . I seem stupid and i cannot figure out why – Divya MV Jan 10 '21 at 07:08
  • Is the proxy address stable? Did something in your network change? Did you change the code? Is HTTP_PROXY also set in the new bash terminal where u call ur code from? – Fabian Jan 10 '21 at 08:55
  • @Fabian proxy address is dependent on the VPNI am connected to...however i am using the same one that my browser uses. i have had network changes but i changed proxies accordingly .. code wise i tried adding basic auth creds to the request( Because when the DNS error was resolved, the target server sent me an unauthorized error in the response), then it started giving some weird memory related errors. on reverting which the DNS error came back. I restored a local copy i had of the working code but that isn't working. later i tried setting HTTP_PROXY from bash as well to no avail. – Divya MV Jan 10 '21 at 17:53
  • Is your proxy maybe requiring an auth now? Maybe something changed hm. Did you follow https://stackoverflow.com/questions/51175487/go-http-proxy-with-auth to add basic auth to the request? Otherwise maybe ask ur company admin on this. You could check how ur browser sends proxy requests with wireshark, but that would probably be overkill hm – Fabian Jan 10 '21 at 20:12

1 Answers1

1

There is a beautiful article on medium on resolving go's DNS issues. Shortly it referes to the Name_Resolution of the net package documentation.

In addition to that try to debug domain resolving from the command line with a dig, ping or any other network-related tools. Maybe you r corporate browser has some additional ways to perform DNS resolution in addition to standard once.

Oleg Butuzov
  • 4,795
  • 2
  • 24
  • 33