
我正在使用gson而不是android进行改造,因为它更快,更安全.
问题是改造是编码特殊字符,如=和?,我正在使用的网址无法解码这些字符.
这是我的代码:
API类:
public interface placeAPI {@GET("/{ID}")public voID getFeed(@Path("ID") TypedString ID,Callback主要课程:
String url = "http://API.beirut.com/BeirutProfile.PHP?"; String next = "profileID=111"; //Creating adapter for retrofit with base url RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).setRequestInterceptor(requestInterceptor).build(); //Creating service for the adapter placeAPI placeAPI = restAdapter.create(placeAPI.class); placeAPI.getFeed(ID,new Callback我尝试使用这个gson方法解决问题,但它没有用,很可能是因为它只包含url的第一部分而不是我发送到placeAPI接口的那部分:
Gson gson = new GsonBuilder().disableHTMLEscaPing().create();并在创建restadapter时添加了这个:
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(url).setRequestInterceptor(requestInterceptor).setConverter(new GsonConverter(gson)).setConverter(new GsonConverter(gson)).build();有什么帮助吗?最佳答案您必须使用Use @Encodedpath.像这样:
public interface placeAPI {@GET("/{ID}")public voID getFeed(@Encodedpath("ID") TypedString ID,Callback注意:以上工作但现在我正在查看文档,似乎@Encodedpath已被弃用,因此请使用@PATH及其参数:
public interface placeAPI {@GET("/{ID}")public voID getFeed(@Path("ID",encode=false) TypedString ID,Callbackref:https://square.github.io/retrofit/2.x/retrofit/ 总结
以上是内存溢出为你收集整理的android – 改造编码特殊字符全部内容,希望文章能够帮你解决android – 改造编码特殊字符所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)