retrofit2

How do I construct and pass raw json data with okHttpClient in android

不问归期 提交于 2020-07-06 05:29:11
问题 I am using a query where I need to POST to an endpoint with okhttpclient. The issue is I have the payload value and the senttime. I just don't know how to create a json object to send over as a raw body object to the endpoint. To make things more clear: here's my postman screenshot: enter image description here This is my post request : https://example.org/api/service-profile/v1/device-notification/ {deviceId} Now I am planning to pass {deviceId} in the path, authorization token in the header

how to display field is missing error response from api using retrofit?

两盒软妹~` 提交于 2020-06-29 03:41:15
问题 I'm making an login page.What i have done is--> 1.When user typed right login details -->it will take him to next successful home page 2.When user typed wrong login details-->displayed an error response from API that email or password is wrong try again later.. So basically what I want is--> When user forgot to fill field like email or password, it should give response from API like "data is missing". Here is my json: { "status": 400, "message": "Data missing.", "user_msg": "Data missing" }

How to add multiple headers with ok Http

a 夏天 提交于 2020-06-27 07:59:10
问题 I am using Retrofit 2 and Okhttp for my android project. I want to add multiple headers in the api request. This is my interceptor code : public class NetworkInterceptors implements Interceptor { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Userid", "10034") .addHeader("Securitykey", "Fb47Gi") .build(); return chain.proceed(request); } } This is not working properly. In server side I am getting

How to inflate progressBar layout without code duplication when there is an api call

夙愿已清 提交于 2020-06-25 02:07:10
问题 I have this flow in my app: declare endpoints: public interface EndPoints { @GET(Constants.POPULAR) Call<AllData> getAllData( @Query("api_key") String apiKey ); } Retrofit service: private static EndPoints endPoints = retrofit.create(EndPoints.class); public static EndPoints getEndpoints() { return endPoints ; } And I call this inside my view model: private void getDataFromApi() { Call<AllData> call = RetrofitService.getEndPoints().getAllData(Constants.API_KEY); call.enqueue(new Callback

Architecture Components Retrofit and RxJava 2 error handling

断了今生、忘了曾经 提交于 2020-06-24 14:09:09
问题 I am currently trying to implement the new ViewModels in the architecture components with an API request from retrofit and Okhttp, everything is working but I can't figure out how to pass an error response from retrofit to LiveDataReactiveStreams.fromPublisher and then upstream to the observer in the fragment. This is what I have so far: public class ShowListViewModel extends AndroidViewModel { private final ClientAdapter clientAdapter; private LiveData<List<Show>> shows; public

Issue to Upload video file from android device to SpringBoot Rest API

混江龙づ霸主 提交于 2020-06-17 13:16:06
问题 I am stuck to achieve below functionality in android actually I dont have much working experience in android new APIs (API 29) 1- Picked video from gallery, it gave me URI and I created IputeStreamRequestBody as per this thread Here is my code for that: public class InputStreamRequestBody extends RequestBody { private final MediaType contentType; private final ContentResolver contentResolver; private final Uri uri; public InputStreamRequestBody(MediaType contentType, ContentResolver

Bad Request [400], FCM Legacy HTTP API with Retrofit

放肆的年华 提交于 2020-06-17 09:42:09
问题 URL = https://fcm.googleapis.com/fcm/send Request Body { "registration_ids": ["token 1","token 2"], "priority": "high", "notification": { "title": "Divine Public School", "body": "Test Message." } } Header { "Content-Type: application/json", "Authorization: key=<myServerKey>" } I am getting status code 200 and even receiving notification in client app when hitting this url from Postman. But when I am trying to do the same in android using retrofit , I am getting status 400 Bad Request.

SSL connection error on valid certificate

℡╲_俬逩灬. 提交于 2020-06-01 02:42:47
问题 I got an javax.net.ssl.SSLHandshakeException: Chain validation failed , when I´m trying to connect to my API server, the certificate is valid nowdays, and in the stack trace I got Caused by: java.security.cert.CertPathValidatorException: Response is unreliable: its validity interval is out-of-date , the certificate is valid and it´s working on iOS and in the website, the problem is only in Android. I´m using Retrofit, here is the clitent generation fun generateClient(): OkHttpClient { val

mocking Retrofit response calls with Call not working

北城余情 提交于 2020-05-26 10:25:07
问题 I'm mocking the response of the APIService. Unfortunately it is not working, I have to send back a Call but I don't understand how. The question is how to send back a Call object. @RunWith(AndroidJUnit4::class) class ApiServiceTest { @Test fun testSomething() { val apiService = ApiServiceMock() val call = apiService.getStep1User() val result = call.execute() Assert.assertEquals("SomeUserValue", result.body()!!.getResponse()) } } Here is the mocked service: class ApiServiceMock : ApiService {

Retrofit getting 400 bad request in local iis server but 200 in post man

醉酒当歌 提交于 2020-05-17 07:49:07
问题 I have local asp .net core 2 IIS server. I am getting result when I am using post request. But I am getting error 400 when I am trying to request from andorid using retrofit2. My android device and server are connected to same wifi network postman returns retrofit return I am using my server pc ip instead of localhost for retrofit because retrofit does not support local host retrofit client @POST("/Auth/authenticate") Call<ApiResponse> createAccount(@Body Request user); retrofit call request