问题
I have such URL https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=Belarus,Minsk,Kuprevicha,1/2&destinations=Belarus,Minsk,Kurchatova,8&key={API_key} and in brovser it counts distance correctly:
{
"destination_addresses" : [ "ул. Курчатова 8, Минск, Беларусь" ],
"origin_addresses" : [
"ул. Академика Купревича 1/2, Минск 220141, Беларусь"
],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "24,5 км",
"value" : 24526
},
"duration" : {
"text" : "20 мин.",
"value" : 1196
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
but when I use org.apache.http.client.fluent.Request:
String req = Request.Get(uri).execute().handleResponse(UTF8_CONTENT_HANDLER);
After executing this code i have such result:
{
"destination_addresses" : [ "Minsk, Belarus" ],
"origin_addresses" : [ "Minsk, Belarus" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "1 m",
"value" : 0
},
"duration" : {
"text" : "1 min",
"value" : 0
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
What am I doing wrong?
回答1:
The problem was not occused by apache Http Client. Google requires specify localiztion explicitely. Probaly for english localization it always works by default. If you append &language=ru to url, it will work correctly.
来源:https://stackoverflow.com/questions/40532561/org-apache-http-client-fluent-corrupts-url