我想向api发送一个请求,其中包含一个包含单引号字符的URL。我正在使用retrofit2。
我想要这个网址到达api: http://someapp.somecompany.com/api/contents/inc()?$ filter = _Id%20eq%20'57fb60534421dd35544b27a9'
我使用(encoded = true)和(encoded = false)属性尝试了@Query和@QueryMap注释,但我的尝试都没有。
MyClient(界面)
@PUT("api/contents/inc()")
Call<Object> addLike(@QueryMap(encoded =true) Map<String,String> options);
MainActivity(活动)
Map<String,String> likeMap = new HashMap<>();
likeMap.put("$filter","_Id%20eq%20'57fb60534421dd35544b27a9'");
Call<Object> addLikeCall = myClient.addLike(likeMap);
addLikeCall.enqueue(new Callback<Object>() {.....});
这段代码给了我这个输出:
- &GT; PUT http://someapp.somecompany.com/api/contents/inc()?$ filter = _Id%20eq%20%2757fb60534421dd35544b27a9%27 http / 1.1(0字节正文)
&lt; - 500内部服务器错误http://someapp.somecompany.com/api/contents/inc()?$ filter = _Id%20eq%20%2757fb60534421dd35544b27a9%27(132ms,36字节正文)
如何避免在url中对我的单引号进行改造?
感谢。
答案 0 :(得分:2)