json - Android Volley : bad urls encoding -


i use volley library requests executing.

when make simple requests address geocoding google maps v3 , receive invalid_request or 400 error.

the problem occurs in urls : http://maps.googleapis.com/maps/api/geocode/json?address=52072,aachen-horbach gzg&region=deu&sensor=false

http://maps.googleapis.com/maps/api/geocode/json?address=362 35,abertamy-horní blatná&region=ita&sensor=false

when use same urls apache defaulthttpclient, works fine.

how pass url :

    stringbuilder addressdepartureurl  = new stringbuilder();     if (order.getdepartureaddress().getstreet()!=null && !order.getdepartureaddress().getstreet().equalsignorecase(""))                         addressdepartureurl.append(order.getdepartureaddress().getstreet() + ", ");     if (order.getdepartureaddress().gethousenumber()!=null && ! order.getdepartureaddress().gethousenumber().equalsignorecase(""))                         addressdepartureurl.append(order.getdepartureaddress().gethousenumber() + ", ");     if (order.getdepartureaddress().getzipcode()!=null && !order.getdepartureaddress().getzipcode().equalsignorecase(""))                         addressdepartureurl.append(order.getdepartureaddress().getzipcode() + "," );     if (order.getdepartureaddress().getcity()!=null && !order.getdepartureaddress().getcity().equalsignorecase(""))                         addressdepartureurl.append(order.getdepartureaddress().getcity() );     if (order.getdepartureaddress().getcountrycode()!=null && !order.getdepartureaddress().getcountrycode().equalsignorecase(""))                         addressdepartureurl.append("&region="+order.getdepartureaddress().getcountrycode() ); addressdepartureurl.append("&sensor=false");     string finaldepartureurl = constants.url_geocoding + addressdepartureurl.tostring();   requestqueue queue = volley.newrequestqueue(getactivity());   jsonobjectrequest jsonobjreq = new jsonobjectrequest(request.method.get,                         url.tostring(), null,                         new response.listener<jsonobject>() {                              @override                             public void onresponse(jsonobject response) {                                 log.i(tag + " getgeocodingresults response", response.tostring());                                 log.i(tag + " flag", integer.tostring(flag));                                 volleyresponse = response;                                 mvolleyresponse.ondatareceived(flag, response, order);                             }                         }, new response.errorlistener() {                      @override                     public void onerrorresponse(volleyerror error) {                         volleylog.d(tag, "error: " + error.getmessage());                         // hide progress dialog                     }                 });                 queue.add(jsonobjreq);  how can receive same results of `apache` library ?  

i found answer. in encoding. workable solution :

      if (order.getdestinationaddress().getstreet() != null && !order.getdestinationaddress().getstreet().equalsignorecase(""))          addressdestinationurl.append(urlencoder.encode(order.getdestinationaddress().getstreet(), "utf-8") + ", ");         if (order.getdestinationaddress().gethousenumber() != null && !order.getdestinationaddress().gethousenumber().equalsignorecase(""))                                 addressdestinationurl.append(urlencoder.encode(order.getdestinationaddress().gethousenumber(), "utf-8") + ", ");         if (order.getdestinationaddress().getzipcode() != null && !order.getdestinationaddress().getzipcode().equalsignorecase(""))                           addressdestinationurl.append(urlencoder.encode(order.getdepartureaddress().getzipcode(), "utf-8") + ",");         if (order.getdestinationaddress().getcity() != null && !order.getdestinationaddress().getcity().equalsignorecase(""))                          addressdestinationurl.append(urlencoder.encode(order.getdepartureaddress().getcity(), "utf-8"));         if (order.getdestinationaddress().getcountrycode() != null && !order.getdestinationaddress().getcountrycode().equalsignorecase(""))     addressdestinationurl.append("&region=" + order.getdestinationaddress().getcountrycode());    addressdestinationurl.append("&sensor=false");          string finaldepartureurl = constants.url_geocoding +addressdepartureurl.tostring(); 

so should encode parameters, not whole query.

symbols & , = shouldn't encoded !


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -