Answer the question
In order to leave comments, you need to log in
How to send a get request with a parameter in Russian?
package geogo
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"strings"
//"time"
"errors"
)
// DefaultTimeout for the request execution
//const DefaultTimeout = time.Second * 8
// ErrTimeout occurs when no response returned within timeoutInSeconds
var ErrTimeout = errors.New("TIMEOUT")
type EndpointBuilder interface {
GeocodeURL(string) string
}
type HTTPGeocoder struct {
EndpointBuilder
}
func Response(ctx context.Context, url string) error {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
req = req.WithContext(ctx)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
body := strings.Trim(string(data), " []")
fmt.Println(url)
fmt.Println(body)
if body == "" {
return nil
}
return nil
}
package main
import(
"context"
"time"
"fmt"
"geogo/geogo"
)
const DefaultTimeout = time.Second * 360
const mapquestAPIKey string = "key"
const searchValue string = "Курган"
const mapquestRequestString string = "https://www.mapquestapi.com/geocoding/v1/address?key="+mapquestAPIKey+"&inFormat=kvp&outFormat=json&location="+searchValue+"&thumbMaps=false" //mapquest string
//Mapquest - проблема с русским языком
func main(){
ctx, cancel := context.WithTimeout(context.TODO(), DefaultTimeout)
defer cancel()
err := geogo.Response(ctx, mapquestRequestString)
fmt.Println(err)
}
https://www.mapquestapi.com/geocoding/v1/address?k...
location":"\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question