retrofit2

Kotlin Android Retrofit 2.6.0 with coroutines error handling

江枫思渺然 提交于 2020-04-07 18:54:59
问题 I am using Retrofit 2.6.0 with coroutines for my web service call. I am getting the API response properly with all response codes (success & error cases). My Issue is when I disconnect the internet(Wifi/mobile data) in between an API call, from the code that I have written, the error is not getting caught properly. The errors most of the time are ConnectException and SocketException. I have tried to catch the error using interceptor and also in from the ViewModel where initiated my call as

Add cookies to retrofit 2 request

半城伤御伤魂 提交于 2020-04-07 17:43:01
问题 I need to add cookies with retrofit 2.0. If i understand correct, cookies - the same as headers. this cookies must be added: private HashMap<String, String> cookies = new HashMap(); cookies.put("sessionid", "sessionId"); cookies.put("token", "token"); this one work with Jsoup lib: String json = Jsoup.connect(apiURL + "/link") .cookies(cookies) .ignoreHttpErrors(true) .ignoreContentType(true) .execute() .body(); here is my code with retrofit request: @GET("link") Call<CbGet> getData(@Header(

Add cookies to retrofit 2 request

a 夏天 提交于 2020-04-07 17:41:27
问题 I need to add cookies with retrofit 2.0. If i understand correct, cookies - the same as headers. this cookies must be added: private HashMap<String, String> cookies = new HashMap(); cookies.put("sessionid", "sessionId"); cookies.put("token", "token"); this one work with Jsoup lib: String json = Jsoup.connect(apiURL + "/link") .cookies(cookies) .ignoreHttpErrors(true) .ignoreContentType(true) .execute() .body(); here is my code with retrofit request: @GET("link") Call<CbGet> getData(@Header(

Upload file using both Multipart and JSON Key value pairs with Retrofit2

◇◆丶佛笑我妖孽 提交于 2020-04-06 03:46:04
问题 Currently we are uoloading files (Video, Audio, Text etc..) by converting String bytes with simple JSON including some other values with their Key-Value pairs. Just like below: Some header values: { "header": { "geoDate": { "point": { "longitude": 77.56246948242188, "latitude": 12.928763389587403 }, "date": "2020-02-25T18:26:00Z" }, "version": "1.35.00.001", "businessId": "178" } } and files info: JSONObject data = new JSONObject(); data.put("name", params.name); data.put("mimeType", params

Same app can't send http request by docker compose

霸气de小男生 提交于 2020-03-23 08:18:39
问题 Spring boot retrofit 2 docker in my docker-compose file: version: "3" services: server: image: asubscriber/eshop:1.0.1 build: . ports: - 8090:8090 Run my app (Spring boot) from console like this: java -jar build/libs/eshop-1.0.1.jar eshop-1.0.1.jar Run success. And success to http request. Here log: [INFO ] 2020-03-14 21:41:09.480 [OkHttp http://localhost:8091/...] OkHttpClient - --> POST http://localhost:8091/api/v1/notifyEmail?emailTo=a_subscriber%40mail.ru&action=order_update&orderId=38

Same app can't send http request by docker compose

扶醉桌前 提交于 2020-03-23 08:18:33
问题 Spring boot retrofit 2 docker in my docker-compose file: version: "3" services: server: image: asubscriber/eshop:1.0.1 build: . ports: - 8090:8090 Run my app (Spring boot) from console like this: java -jar build/libs/eshop-1.0.1.jar eshop-1.0.1.jar Run success. And success to http request. Here log: [INFO ] 2020-03-14 21:41:09.480 [OkHttp http://localhost:8091/...] OkHttpClient - --> POST http://localhost:8091/api/v1/notifyEmail?emailTo=a_subscriber%40mail.ru&action=order_update&orderId=38

How to store data in room database after fetching from server

∥☆過路亽.° 提交于 2020-03-14 04:57:30
问题 I am using Retrofit2 and Rxjava2 in my android app as a networking library and NodeJS and MongoDB as a backend service.I want to fetch data from server and store data in room database in order to if user open app again it fetches data from room and not from server until some new data is added on server. So far I have successfully fetched data from server and showing it in recycler view. What I want to achieve: 1) Store data in room database after fetching from server. 2) Show data from room

How to store data in room database after fetching from server

前提是你 提交于 2020-03-14 04:57:29
问题 I am using Retrofit2 and Rxjava2 in my android app as a networking library and NodeJS and MongoDB as a backend service.I want to fetch data from server and store data in room database in order to if user open app again it fetches data from room and not from server until some new data is added on server. So far I have successfully fetched data from server and showing it in recycler view. What I want to achieve: 1) Store data in room database after fetching from server. 2) Show data from room

Retrofit 2.0 Multipart Request, send boolean type in form data including file

南楼画角 提交于 2020-03-11 13:20:40
问题 I am trying to upload a file using retrofit 2.0. Apart from file, I have few other params to be send with form data which include a boolean type also. My request declaration is - @Multipart @POST("/upload/abc") Call<UploadResponse> uploadToServer(@Part("img_file\";filename=\"image") RequestBody file, @Part("access_token") RequestBody sessionKey, @Part("is_final") Boolean isFinal, @Part("sequence_id") Integer sequenceId, @Part("entity_id") RequestBody entityId, @Part("image_type") RequestBody

Retrofit 2.0 Multipart Request, send boolean type in form data including file

独自空忆成欢 提交于 2020-03-11 13:18:16
问题 I am trying to upload a file using retrofit 2.0. Apart from file, I have few other params to be send with form data which include a boolean type also. My request declaration is - @Multipart @POST("/upload/abc") Call<UploadResponse> uploadToServer(@Part("img_file\";filename=\"image") RequestBody file, @Part("access_token") RequestBody sessionKey, @Part("is_final") Boolean isFinal, @Part("sequence_id") Integer sequenceId, @Part("entity_id") RequestBody entityId, @Part("image_type") RequestBody