org.apache.http.client.fluent corrupts URL

会有一股神秘感。 提交于 2019-12-10 11:55:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!