NobleSiks
NobleSiks

Reputation: 369

http: server gave HTTP response to HTTPS client

I am using go to consume the google maps geocoding API, but I keep getting this error:

The HTTP request failed with error Get https://maps.googleapis.com /maps/api/geocode/json?address=Bangalore&key=KEY: http: server gave HTTP response to HTTPS client

The url in the error works fine in my browser and gives the appropriate response, but won't give what I want in the code snippet below:

package main

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

func main()  {
    key := "mysecretkey"
    location := "Bangalore"
    url := "https://maps.googleapis.com/maps/api/geocode/json?address="+location+"&key="+key
    fmt.Println("Starting the application...")
    response, err := http.Get(url)

    if err!=nil{
        fmt.Printf("The HTTP request failed with error %s\n", err)
    }else {
        data, _ := ioutil.ReadAll(response.Body)
        fmt.Println(string(data))
    }
}

Upvotes: 9

Views: 17288

Answers (2)

Poovarasan1028
Poovarasan1028

Reputation: 1

Iam just change by http.post("https://localhost:8080) to http.post("http://localhost:8080"). Just remove a s in https. Its work :-)

Upvotes: -5

NobleSiks
NobleSiks

Reputation: 369

The problem was with the proxy, which probably caused some certificate issues. Works fine without proxy .

Upvotes: 3

Related Questions