retrofit2

How to Handle Two Different Response in Retrofit

大憨熊 提交于 2020-02-28 15:56:15
问题 I followed this to POST Data Using Retrofit2 I Used JSON POJO to Parse my POST and GET files So Here If Data inside the Records Is there I will get This Kind of Response { "status": "200", "response": [{ "cnt_id": "201", "phn_no": "3251151515", "dat_cnt": "Reset Password request Said to Mail" }, { "cnt_id": "209", "phn_no": "555465484684", "dat_cnt": "Hi DEMO User , Congratulations! Your account has been created successfully." }, { "cnt_id": "210", "phn_no": "4774748", "dat_cnt": "Hi XYZ ,

How to Handle Two Different Response in Retrofit

断了今生、忘了曾经 提交于 2020-02-28 15:54:46
问题 I followed this to POST Data Using Retrofit2 I Used JSON POJO to Parse my POST and GET files So Here If Data inside the Records Is there I will get This Kind of Response { "status": "200", "response": [{ "cnt_id": "201", "phn_no": "3251151515", "dat_cnt": "Reset Password request Said to Mail" }, { "cnt_id": "209", "phn_no": "555465484684", "dat_cnt": "Hi DEMO User , Congratulations! Your account has been created successfully." }, { "cnt_id": "210", "phn_no": "4774748", "dat_cnt": "Hi XYZ ,

Android| Basic Auth using retrofit2 and local API

最后都变了- 提交于 2020-02-28 15:41:49
问题 I started making an app and connected it to a mock API at first. Now I want to connect it an API that runs on my PC. For starters, I'm trying to implement the login access. Since my API's base URL was http://localhost:5000/energy/api/ I changed it to http://<< MyIPAddress >>:5000/energy/api/ (don't know if this is right yet). I'm testing it on my actual phone. But with my code username and password are passed on as parameters, while I'd like to login with basic auth (this is how I do it in

Android| Basic Auth using retrofit2 and local API

青春壹個敷衍的年華 提交于 2020-02-28 15:36:02
问题 I started making an app and connected it to a mock API at first. Now I want to connect it an API that runs on my PC. For starters, I'm trying to implement the login access. Since my API's base URL was http://localhost:5000/energy/api/ I changed it to http://<< MyIPAddress >>:5000/energy/api/ (don't know if this is right yet). I'm testing it on my actual phone. But with my code username and password are passed on as parameters, while I'd like to login with basic auth (this is how I do it in

How to add Api_KEY into interceptor using okhttp

让人想犯罪 __ 提交于 2020-02-24 06:56:24
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

馋奶兔 提交于 2020-02-24 06:56:02
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to add Api_KEY into interceptor using okhttp

為{幸葍}努か 提交于 2020-02-24 06:55:00
问题 I have this service where I want to put the token as an interception in the okhttp instead of passing as a parameter with @Header("MY_API_KEY") This is my code regarding the service /** * Provides the [PHService] */ fun provideService(): PHService { val logger = HttpLoggingInterceptor() logger.level = HttpLoggingInterceptor.Level.BASIC val client = OkHttpClient.Builder() .addInterceptor(logger) .build() return Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .client(client)

How to register custom TypeAdapter or JsonDeserializer with Gson in Retrofit?

家住魔仙堡 提交于 2020-02-06 07:30:06
问题 I am using Retrofit in my project and I need some custom deserialization with some of the responses that the API I use returns. Just for an example: I receive JSON like: { "status": "7 rows processed" } ( will be "0 rows processed" if request failed ) and I need to deserialize to an object like: @Getter @RequiredArgsConstructor public static class Result { private final boolean success; } I have created custom deserializer: public class ResultDeserializer implements JsonDeserializer<Result> {

how to send List<String> with retrofit?

爱⌒轻易说出口 提交于 2020-02-04 12:58:07
问题 I'm sending a multipart request to server and this is my interface: @Multipart @POST("v1/group/new") Call<MyResponse> newGroup( @Header("token") String token, @Part MultipartBody.Part photo, @Part("title") RequestBody subject, @Part("members") List<RequestBody> members); and for sending my members in my fragment, I change my List<String> to List<RequestBody> as below: List<RequestBody> members = new ArrayList<>(); for(int i = 0;i < membersId.size(); i++){ members.add(RequestBody.create

How to retrieve specific data from json array via retrofit2 using gson parsing

让人想犯罪 __ 提交于 2020-02-04 05:29:25
问题 Here is the JSON response from a server (which i cannot change the structure of) My issues are as follows: 1. The data changes based on the query so sometimes the Primary posts & Secondary Posts are an array and sometimes they are an object/ string. How would i go about retrieving a value from Address without getting the whole structure? Eg. only retrieve Email & post code strings from MainAddress only retrieve Address1 from Website & Twitter { "Members": { "Member": { "@First_Id": "000", "