0) 我正在使用 Retrofit 2 来处理.
1)我有一些界面:
public interface ApiService {
@GET("statdirectory/exchange")
Call<List<MyModel>> getСurrency(@Query("date") String inputDate);
}
2)当我调用方法时getСurrency(someParametr),其中 someParametr 是字符串,与“date&json”一致(例如“20170917&json”):
ApiService apiService = RetrofitController.getApi();
apiService.getCurrency("20170917&json").enqueue(new Callback<List<MyModel>>() {
@Override
public void onResponse(Call<List<MyModel>> call, Response<List<MyModel>> response) {
call.request().url();
Log.e("URL", call.request().url()+"");
response.code();
Log.e("CODE", response.code()+"");
}
//.....
3)我看到:
URL: "https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20170917 https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20170917%26json" (&被替换为%26)
CODE: "404"
4)我添加的inmy界面encoded:
getСurrency(@Query(value="date", encoded=false) String inputDate);
But 我的结果与步骤 3 相同!
5)如何检查这个问题?如何在不使用的情况下获取URL%26在我的绳子上?我阅读了其他有类似问题的问题,但没有解决我的问题。谢谢!
我只是想澄清一下,最初的问题是编码参数需要为真:encoded=
true。这表明提供的值已经被编码,因此不需要通过改造重新编码。正如改造文档中所述,默认值encoded
是假的。 IE:
getСurrency(@Query(value="date", encoded=true) String inputDate);
将生成正确的 url。
该文档说明了以下有关encoded
范围:
指定参数名称和值是否已经是 URL
编码。
Source: https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Query.html https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Query.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)