I am trying to access a URL that gives me a JSON response, and said URL is only accessible when I am connected to my company's VPN.
Using the Standard Golang Library, the code below is getting an error even when I am connected to my company's VPN:
myClient := &http.Client{}
req, err := http.NewRequest("POST", "https://mysite/getJSONResponse", nil)
req.Header.Add("myHeader", "myHeaderValue")
resp, err := myClient.Do(req)
Here is the error I am getting:
502 Bad Gateway: Registered endpoint failed to handle the request.
However, this code (also from the Standard Library) is able to get the JSON response when I am connected to my company's VPN:
envDialer := proxy.FromEnvironment()
myTransport := &http.Transport{Dial: envDialer.Dial}
myClient := &http.Client{Transport: myTransport}
req, err := http.NewRequest("POST", "https://mysite/getJSONResponse", nil)
req.Header.Add("myHeader", "myHeaderValue")
resp, err := myClient.Do(req)
My problem is that when I push the working code to Cloud Foundry (which is also connected to my company's VPN), my code is getting the below error instead:
Post https://mysite/getJSONResponse: read tcp 10.254.2.182:45320->165.156.25.94:443:
read: connection reset by peer
It is as if the code is unable to connect to my company's VPN even when it is already Pushed to Cloud Foundry, which is why the URL refused to give the JSON response.
However, when I try to access the same URL in Cloud Foundry with a test Web Application that uses the Beego framework, it is able to get the JSON response just fine.
I should mention that the Beego version works even when the http_proxy, https_proxy, and no_proxy environment variables are not set:
req := httplib.Post("https://mysite/getJSONResponse")
req.Header("myHeader", "myHeaderValue")
str, err := req.String()
if err != nil {
fmt.Println(err)
}
beego.Info(str)
u.Data["json"] = str
u.ServeJSON()
My questions are:
Why is the second Standard Library code working fine locally, but not when Pushed to Cloud Foundry?
What is the Beego framework doing behind the scenes that lets it connect to my company's VPN over at Cloud Foundry, and can the same be done with the Standard Library?
I've got a feeling Beego is doing something to its Proxy/Port settings to enable it to connect to our company's VPN.
I really don't want to have to integrate our back-end codes with the Beego framework just to connect to our company's VPN. I must be missing something really simple which can be done with the Standard Library. Any ideas?