为什么retrofit2在URL末尾添加斜杠?

时间:2016-09-30 11:54:39

标签: java android retrofit2

我正在使用retrofit2从我的wordpress网站上获取帖子的应用程序,在我的界面中我有这个方法来获取作者头像

@GET("user/get_userinfo" + &insecure=cool)
Call<CallbackAuthorAvatar> getAuthorAvatar(
        @Query("user_id") int id
);

实施后,网址将是“http://mywebsite.org/api/user/get_userinfo/?user_id=1&insecure=cool/

这不起作用,因为URL末尾的斜杠

问我怎样才能删除斜杠?

我的RestAdapter

public class RestAdapter {
public static API createAPI() {

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

    Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return false;
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    }).create();

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .build();

    OkHttpClient.Builder client = new OkHttpClient.Builder();
    client.addInterceptor(logging);


    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(API.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .client(okHttpClient)
            .build();


    return retrofit.create(API.class);
}
}

0 个答案:

没有答案