0

Im trying to understand the URLEncoder class.It says that URLs must be properly encoded in order for it to work for when attempting to access the resource. So A URL cant have any spaces in them. So does the URLEncoder class replaces those blank spaces with some sort of value? and if so, Which?

Also I see that you only are suppose to encode the data you add onto the URL, not the entire URL.

How could i encode the data that is entered by the user to add to the URL?

Heres an example:

String url = "https://www.sample.com/folders/v1/volumes?q="+search;

  • use okhttp http://square.github.io/okhttp/ – Tomasz Mularczyk Feb 27 '16 at 21:24
  • 1
    http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters https://en.wikipedia.org/wiki/Query_string#URL_encoding – Mrusful Feb 27 '16 at 21:25
  • Thanks Mrusful! It cleared up a lot for me. But when i try: String url = "https://www.sample.com/folders/v1/volumes?q="+ URLEncoder.encode(search); it gives me a Error of : warning: [deprecation] encode(java.lang.String)in java.net.URLEncoder has been deprecated. Any ideas why? – iHateAndroidDev Feb 27 '16 at 21:31
  • i think here need use google and read basics http://stackoverflow.com/questions/213506/java-net-urlencoder-encodestring-is-deprecated-what-should-i-use-instead – Mrusful Feb 27 '16 at 21:36
  • I have tried this: String url = "https://www.googleapis.com/books/v1/volumes?q="; try { URLEncoder.encode(search,"UTF-8"); } catch (UnsupportedEncodingException e) { Log.e("utf8", "conversion", e); } I get no errors but nothing shows up on the screen. =( – iHateAndroidDev Feb 27 '16 at 22:30

0 Answers0