5

This is related to this other question. I'm fetching a URL through a proxy using this simple code:

package main

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

func main() {
    proxyUrl, err := url.Parse("87.236.233.92:8080")
    httpClient := &http.Client { Transport: &http.Transport { Proxy: http.ProxyURL(proxyUrl) } }
    response, err := httpClient.Get("http://stackoverflow.com")
    if err != nil {
        fmt.Println(err.Error())
    } else {
        body, _ := ioutil.ReadAll(response.Body)
        fmt.Println("OK: ", len(body))
    }
}

If I run this code, I am getting this error:

Get http://stackoverflow.com: http: error connecting to proxy 87.236.233.92:8080: GetServByName: The requested name is valid, but no data of the requested type was found.

I know that the proxy address is valid and if I fetch the URL through the proxy by other means it work. Any idea why I'm getting this error?

1 Answer 1

10

Specify your proxy with http:// in and it should work, eg

proxyUrl, err := url.Parse("http://87.236.233.92:8080")
if err != nil {
    fmt.Println("Bad proxy URL", err)
    return
}
Sign up to request clarification or add additional context in comments.

Comments

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.