Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL Parameter Encoding fails #1058

Closed
jjoe64 opened this issue Sep 5, 2015 · 2 comments
Closed

URL Parameter Encoding fails #1058

jjoe64 opened this issue Sep 5, 2015 · 2 comments
Milestone

Comments

@jjoe64
Copy link

jjoe64 commented Sep 5, 2015

Hi I'm trying to do a simple http get query via Retrofit.

My parameter has some special characters and it seems that the url encoding fails.

Original:

data=[out:json];node["name"~"Karlsruhe"]["place"~"city|village|town"];out body;

correct encoding should look like this:

data=%5Bout%3Ajson%5D%3Bnode%5B%22name%22~%22Karlsruhe%22%5D%5B%22place%22~%22city%7Cvillage%7Ctown%22%5D%3Bout%20body%3B

but Retrofit creates this:

data=[out:json];node[%22name%22~%22Karlsruhe%22][%22place%22~%22city|village|town%22];out%20body;

and this will fail with:

java.lang.IllegalStateException: not valid as a java.net.URI:
http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];node[%22name%22~%22Karlsruhe%22][%22place%22~%22city|village|town%22];out%20body;
at com.squareup.okhttp.HttpUrl.uri(HttpUrl.java:336) at
com.squareup.okhttp.internal.http.RouteSelector.resetNextProxy(RouteSelector.java:135)
at
com.squareup.okhttp.internal.http.RouteSelector.(RouteSelector.java:71)
at
com.squareup.okhttp.internal.http.RouteSelector.get(RouteSelector.java:76)
at
com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:321)
at
com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
at com.squareup.okhttp.Call.getResponse(Call.java:267) at
com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at
com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.execute(Call.java:79) at
retrofit.OkHttpCall.execute(OkHttpCall.java:112)

What can be done here to fix this encoding issue?
Thanks

@JakeWharton
Copy link
Member

I don't think your OkHttp change was enough. On its latest master:

HttpUrl url = new Builder() //
    .scheme("http")
    .host("example.com")
    .addPathSegment("data=[out:json];node[\"name\"~\"Karlsruhe\"][\"place\"~\"city|village|town\"];out body;")
    .build();
System.out.println(url);
System.out.println(url.uri());

yields:

http://example.com/data=[out:json];node[%22name%22~%22Karlsruhe%22][%22place%22~%22city%7Cvillage%7Ctown%22];out%20body;
Exception in thread "main" java.lang.IllegalStateException: not valid as a java.net.URI: http://example.com/data=[out:json];node[%22name%22~%22Karlsruhe%22][%22place%22~%22city%7Cvillage%7Ctown%22];out%20body;

@JakeWharton
Copy link
Member

Moved to square/okhttp#1872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants