久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Retrofit 2 向所有請(qǐng)求添加標(biāo)頭

Adding header to all request with Retrofit 2(使用 Retrofit 2 向所有請(qǐng)求添加標(biāo)頭)
本文介紹了使用 Retrofit 2 向所有請(qǐng)求添加標(biāo)頭的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

Retrofit 2 的文檔 說:

可以使用 OkHttp 攔截器指定需要添加到每個(gè)請(qǐng)求的標(biāo)頭.

Headers that need to be added to every request can be specified using an OkHttp interceptor.

使用以前的版本可以輕松完成,這里是相關(guān)的QA.

It can be done easily using the previous version, here's the related QA.

但是使用改造 2,我找不到類似 setRequestInterceptorsetInterceptor 方法可以應(yīng)用于 Retrofit.Builder 對(duì)象.

But using retrofit 2, I couldn't find something like setRequestInterceptor or setInterceptor method that can be applied to Retrofit.Builder object.

另外,OkHttp 中似乎沒有 RequestInterceptor 了.Retrofit 的文檔將我們引向 Interceptor 我不太明白如何使用它目的.

Also it seems that there's no RequestInterceptor in OkHttp anymore. Retrofit's doc refers us to Interceptor that I didn't quite understand how to use it for this purpose.

我該怎么做?

推薦答案

OkHttpClient.Builder httpClient = new OkHttpClient.Builder();

httpClient.addInterceptor(new Interceptor() {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request().newBuilder().addHeader("parameter", "value").build();
        return chain.proceed(request);
    }
});
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(url).client(httpClient.build()).build();

這篇關(guān)于使用 Retrofit 2 向所有請(qǐng)求添加標(biāo)頭的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 91精品久久久久久久久 | 日美女逼逼 | 国产精品一区一区三区 | 韩日精品一区 | 久久久久久国产 | 日韩在线三级 | 91爱爱·com | 中文字幕免费 | 欧美午夜精品理论片a级按摩 | 日本精品一区二区 | 福利视频三区 | 亚洲高清中文字幕 | 亚洲精品久久久蜜桃网站 | 欧洲尺码日本国产精品 | 91久久久久久 | 国产精品视频一区二区三区不卡 | 欧美日韩电影在线 | 日韩欧美亚洲综合 | 91在线电影 | 国产一区精品在线 | 国产精品揄拍一区二区 | 精品一二三区在线观看 | 狠狠干影院 | 国产一区二区在线视频 | 久久噜噜噜精品国产亚洲综合 | 一级黄色录像片子 | 人人看人人射 | 国产 日韩 欧美 在线 | 男人天堂手机在线视频 | 噜噜噜噜狠狠狠7777视频 | 国产成人免费视频网站视频社区 | 欧美日韩a| 天天夜碰日日摸日日澡 | 亚洲国产一 | 欧美一级片在线看 | 国产人成精品一区二区三 | 一区二区三区在线观看视频 | 欧美在线一区二区三区 | 日韩美女一区二区三区在线观看 | 毛片视频网站 | 亚洲成人免费在线观看 |