Java 创建url时避免对数据进行编码
我试着这样打电话:Java 创建url时避免对数据进行编码,java,android,url,encoding,retrofit2,Java,Android,Url,Encoding,Retrofit2,我试着这样打电话: @GET(AppConstants.BASE_URL + "{category_type}/") Call<JsonObject> callCustomFilterApI(@Path("category_type") String type, @QueryMap(encoded = true) Map<String,Strin
@GET(AppConstants.BASE_URL + "{category_type}/")
Call<JsonObject> callCustomFilterApI(@Path("category_type") String type,
@QueryMap(encoded = true) Map<String,String> fields ,
@Query("page") String pageNo);
使用
拦截器
并将%26
转换为&
:
class RequestInterceptor implements Interceptor {
@Override
Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
String stringurl = request.url().toString();
stringurl = stringurl.replace("%26", "&");
Request newRequest = new Request.Builder()
.url(stringurl)
.build();
return chain.proceed(newRequest);
}
}
将此设置为您的OkHttp
builder:
OkHttpClient client = new OkHttpClient.Builder();
client.addInterceptor(new RequestInterceptor());
@NILESHARTHOD value参数不适用于QueryMap字段如何将数据添加到
QueryMap
?使用OkHttp
OkHttpClient client = new OkHttpClient.Builder();
client.addInterceptor(new RequestInterceptor());