嗨我想通過Retrofit
做一個簡單的http獲取查詢。翻新無效URI
我的參數有一些特殊字符,看起來URL編碼失敗。
原文:
data=[out:json];node["name"~"Karlsruhe"]["place"~"city|village|town"];out body;
正確的編碼應該是這樣的:
data=%5Bout%3Ajson%5D%3Bnode%5B%22name%22~%22Karlsruhe%22%5D%5B%22place%22~%22city%7Cvillage%7Ctown%22%5D%3Bout%20body%3B
但改造創造這樣的:
data=[out:json];node[%22name%22~%22Karlsruhe%22][%22place%22~%22city|village|town%22];out%20body;
,這將失敗:
java.lang.IllegalStateException:作爲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; 在com.squareup.okhttp.HttpUrl.uri(HttpUrl.java:336)在 com.squareup.okhttp.internal.http.RouteSelector.resetNextProxy(RouteSelector.java:135) 在 com.squareup.okhttp.internal .http.RouteSelector。(RouteSelector.java:71) 在 com.squareup.okhttp.internal.http.RouteSelector.get(RouteSelector.java:76) 在 com.squareup.okhttp.internal.http.HttpEngine。在 com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245) 連接(HttpEngine.java:321) 在com.squareup.okhttp.Call.getResponse(Call.java:267)在 com.squareup.okhttp.Call $ ApplicationInterceptorChain.proceed(Call.java:224)(Call.java:79) retrofit.OkHttpCall.execute(OkHttpCall.java:112) )
在這裏可以做些什麼來解決這個編碼問題? 謝謝
這將在OkHttp 2.6.0-SNAPSHOT中修復。 –