retrofit2

Retrofit 2.0: getting response code 200 but not getting the desired data

旧城冷巷雨未停 提交于 2019-12-23 12:50:37
问题 A very disappointing feature of Retrofit 2.0 is that it does not exactly tell where it fails in parsing the response. Hence, In postman when I hit the request with same body, I get a login response as: { "result": "success", "response_code": 200, "data": { "id": "1", "display_name": "admin", "email": "payal@teckmovers.com", "username": "admin", "access_token": "8daa8e02ca432e51ae90912fbf63eeea" } } But when I hit the exact same request with exactly the same body in Retrofit, I get a very

OkHttp and Retrofit, refresh token with concurrent requests

亡梦爱人 提交于 2019-12-23 08:17:07
问题 In my application I implemented Retrofit to call WebServices and I'm using OkHttp to use Interceptor and Authenticator. Some requests need token, and I have implemented Authenticator interface to handle the refresh (following the official documentation). But I have the following issue : time to time in my app I have to call more than one request at once. Because of that, for one of them I will have the 401 error. Here is my code for request calls : public static <S> S

Retrofit Adding tag to the original request object

此生再无相见时 提交于 2019-12-23 07:57:21
问题 I'm trying to solve a problem where I'll be making a couple of asynchronous calls and based on the original request, I'm performing a task. To solve this issue, I'm trying to add a TAG to each request and then on successful response, I can get the tag and take action based on the tag. Here, I'm using TAG only to identify the original request. Problem Before calling the enqueue method, I'm setting the tag to the original request. But when I get the response in the successful callback, I'm

Getting a Unexpected JDWP Error: 103 while trying to upload an image using retrofit to an api server android?

本秂侑毒 提交于 2019-12-23 07:38:09
问题 I'm getting the following 103 error message while trying to upload an image on the api server using retrofit multipart, the api receives an api token, "_method":"PUT" and image url as parameters, on response receives the complete JSON but with the previous or default image link, the current selected image does not upload, everything else is optional, any help would be appreciated, code is listed below thanks. Also main method is POST but "_method":"PUT" parameter lets you upload the image,

Unit testing, custom Call class for retrofit2 request: Reponse has private access

谁说我不能喝 提交于 2019-12-23 05:23:55
问题 When I create custom Call class I can't return Response, because Response class is final. Is there any workaround for this? public class TestCall implements Call<PlacesResults> { String fileType; String getPlacesJson = "getplaces.json"; String getPlacesUpdatedJson = "getplaces_updated.json"; public TestCall(String fileType) { this.fileType = fileType; } @Override public Response execute() throws IOException { String responseString; InputStream is; if (fileType.equals(getPlacesJson)) { is =

android retrofit2 could not add header (415 error code)

一笑奈何 提交于 2019-12-23 04:55:10
问题 I'm trying to access ticket data via skyscanner api and pass it to my view, but I cannot accomplish that, because I get 415 error code I'm using retrofit2 and adding header programmatically. My interface looks like this: public interface GetFlightDetails { @POST("apiservices/pricing/v1.0/") Call<TicketData> getFlightList(@Query("apiKey") String apiKey, @Query("country") String country, @Query("currency") String currency, @Query("locale") String locale, @Query("originPlace") String originPlace

How to use gson TypeAdapter in Retrofit 2?

混江龙づ霸主 提交于 2019-12-23 03:34:16
问题 I have a working code wherein my retrofit client can retrieve a List of objects(country) from an api. The problem is, the parameter used by the api returns an ARRAY if I used to retrieve all the countries then it returns a single OBJECT when I want to query for a single country. As a result the following exception is shown. java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 4 column 17 path $.RestResponse.result By the way, I'm using Retrofit 2. I tried the

Android Retrofit 2 file upload is not working

旧时模样 提交于 2019-12-22 14:17:15
问题 I want to develop an app which is upload any type of file to sever. I got source code. But it is working only for images. And only upload below 2 MB size of image files. I want to upload all type of files. Please help me. My codes are shown below. MainActivity.java public class MainActivity extends AppCompatActivity { Service service; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button)

Dagger 2 injecting two retrofit objects

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:33:33
问题 I'm using Dagger 2 with retrofit2 library while using MVP. Everything went well till I tried to integrate another service (basically I tried to initialize another retrofit object to another service). I followed this answer but without any success. Every time I'm getting an errors that each of my fragments and application classes don't seem to recognize the component classes. error: cannot find symbol class DaggerApplicationComponent error: cannot find symbol class DaggerEpisodeComponent Code

How to post data using HashMap in retrofit?

与世无争的帅哥 提交于 2019-12-22 08:37:12
问题 Can you please explain how to post data using hashmap in retrofit2 ? 回答1: This is what I post @FormUrlEncoded @POST("getProfile") Call<YourResponseObject> getProfile(@FieldMap HashMap<String, String> data); And the HashMap HashMap<String, String> map = new HashMap<>(); map.put("token", "yourtoken"); map.put("yourvariable", "yourvariable"); 回答2: From Retrofit2 documentation check FieldMap for more details You need to create your interface public interface YourPostService { @FormUrlEncoded