retrofit

Retrofit2.0添加Header的方法总结

点点圈 提交于 2020-08-05 20:44:34
最近在项目里面需要添加header,然后就想大家分想一下retrofit添加header的方法 (1)使用注解的方式添加一个header参数 public interface ApiService { @Headers ( "Cache-Control: max-age=560000" ) @GET ( "/data" ) Call<List<Data>> getData(); } (2)使用注解的方式添加多个header参数 public interface ApiService { @Headers ({ "Accept: application/vnd.yourapi.v1.full+json" , "User-Agent: YourAppName" }) @GET ( "/data/{user_id}" ) Call<Data> getData( @Path ( "user_id" ) long userId); } (3)使用注解的方式,header参数每次都不同,动态添加header public interface ApiService { @GET ( "/data" ) Call<List<Data>> getData( @Header ( "Content-Range" ) String contentRange); } (4)在代码里添加header

How to save pdf in scoped storage?

孤街醉人 提交于 2020-07-31 04:36:48
问题 Before the introduction of scoped storage i was using Download Manager to download pdf in my app and get the pdf from getExternalStorageDirectory , but due to scoped storage i can no longer use getExternalStorageDirectory as it is deprecated. I decided to move away from Download Manager as well as it downloads files in public directory and instead use retrofit to download pdf file. I know i can use the requiredLegacyStorage tag in Android Manifest but it wont be applicable to Android 11 so i

datepicker value from edittext using Retrofit post request

烂漫一生 提交于 2020-07-31 04:16:10
问题 im using retrofit post request method to post date from edittext(date retrieved from datepicker)...when i select date from datepicker and select date on it..it is displaying right date on edittext...but when i submit and check on postman it is showing wrong date.. need help thanks following is my code: val myCalendar: Calendar = Calendar.getInstance() val edittext1 = findViewById(R.id.dob) as EditText val date = OnDateSetListener { view, year, monthOfYear, dayOfMonth -> // TODO Auto-generated

Android网络库的比较:OkHTTP,Retrofit和Volley [关闭]

℡╲_俬逩灬. 提交于 2020-07-26 11:15:39
问题: Two-part question from an iOS developer learning Android, working on an Android project that will make a variety of requests from JSON to image to streaming download of audio and video: 来自学习Android的iOS开发人员的一个分为两个部分的问题,该问题涉及一个Android项目,该项目将提出从JSON到图像到音频和视频流下载的各种请求: On iOS I have used the AFNetworking project extensively. 在iOS上,我广泛使用了 AFNetworking 项目。 Is there an equivalent library for Android? 是否有适用于Android的等效库? I've read up on OkHTTP and Retrofit by Square, as well as Volley but don't yet have experience developing with them. 我已经阅读了Square的 OkHTTP 和 Retrofit ,以及 Volley, 但还没有与它们一起开发的经验。 I'm

Retrofit trailing slash on relative urls

a 夏天 提交于 2020-07-19 06:14:38
问题 Does Retrofit remove the trailing slash from a relative url for an endpoint? I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash. 回答1: You need to manually add the slash at the end of the base URL endpoint. Let's say you have this two instances of retrofit: No Slash Retrofit retrofitNoSlash = new Retrofit.Builder() .baseUrl("https:/

Retrofit trailing slash on relative urls

☆樱花仙子☆ 提交于 2020-07-19 06:13:22
问题 Does Retrofit remove the trailing slash from a relative url for an endpoint? I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash. 回答1: You need to manually add the slash at the end of the base URL endpoint. Let's say you have this two instances of retrofit: No Slash Retrofit retrofitNoSlash = new Retrofit.Builder() .baseUrl("https:/

Retrofit 2 - Is it possible to get the size of a JSON that I'm sending and receiving?

让人想犯罪 __ 提交于 2020-07-18 21:06:10
问题 I need to build a traffic monitor on my Android app, and I need to have stored the size of all json that I'm sending and receiving through retrofit. Using log I can see the actual size of it, but I haven't find a way to get this information so I could save it. I can't get the response.raw either since it's already been parsed to my classes. Is there any way to achieve that? EDIT: Marked vadkou answer as the best one. Instead of creating a new interceptor, I passed the lamda expression:

Retrofit 2 - Is it possible to get the size of a JSON that I'm sending and receiving?

狂风中的少年 提交于 2020-07-18 21:04:48
问题 I need to build a traffic monitor on my Android app, and I need to have stored the size of all json that I'm sending and receiving through retrofit. Using log I can see the actual size of it, but I haven't find a way to get this information so I could save it. I can't get the response.raw either since it's already been parsed to my classes. Is there any way to achieve that? EDIT: Marked vadkou answer as the best one. Instead of creating a new interceptor, I passed the lamda expression:

Kotlin Coroutines suspend fun + retrofit throws “No Retrofit annotation found” error

你。 提交于 2020-07-15 15:16:11
问题 I'm trying to use retrofit's coroutine support in 2.5.1-SNAPSHOT but I keep getting a strange exception. My retrofit service class has: @GET("weather") suspend fun getForecast(@Query("q") query: String, @Query("num_of_days") numDays: String = "1", @Query("format") format : String = "json", @Query("key") apiKey: String = API_KEY) : Weather And when I try to call it I get: 2019-05-18 13:57:01.507 27422-27477/com.my.app E/MainPresenter$onResume$$inlined$CoroutineExceptionHandler: Something went

Kotlin Coroutines suspend fun + retrofit throws “No Retrofit annotation found” error

拈花ヽ惹草 提交于 2020-07-15 15:16:07
问题 I'm trying to use retrofit's coroutine support in 2.5.1-SNAPSHOT but I keep getting a strange exception. My retrofit service class has: @GET("weather") suspend fun getForecast(@Query("q") query: String, @Query("num_of_days") numDays: String = "1", @Query("format") format : String = "json", @Query("key") apiKey: String = API_KEY) : Weather And when I try to call it I get: 2019-05-18 13:57:01.507 27422-27477/com.my.app E/MainPresenter$onResume$$inlined$CoroutineExceptionHandler: Something went