retrofit2

Retrofit with OkHTTP not set Content-Type with @FormUrlEncoded

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 03:36:08
问题 I'm trying to implement auth via x-www-form-urlencoded with Retrofit 2 on Android but faced a problem, that Header Content-Type not set with @FormUrlEncoded annotation, as well as I'm trying to set it manually, but when I'm setting it with a typo like Cotent-Type it works correctly and I can see it in headers. Retrofit version: 2.4.0 So my question: why @FormUrlEncoded not set a content type as well as @Header annotation or what can remove it from headers. My request: @FormUrlEncoded @POST(

How to Post image and data in android retrofit

不想你离开。 提交于 2019-12-25 02:07:36
问题 I am unable to post data and image using retrofit. can u please help me @Multipart @POST("click_and_post") Call<ResponseBody> clicPost( @Part ("click_and_post[image]") RequestBody file, @Part ("click_and_post[category_id]") String category_id, @Part ("click_and_post[brand_id]") String brand_id, @Part ("click_and_post[location]") String location); POst man I am unable to send data can u help me 回答1: This is how you should implement this api int size = youImagePathList.size(); MultipartBody

Retrofit Sending Json

半世苍凉 提交于 2019-12-25 01:05:07
问题 I need to send a Json to a payment gateway through Retrofit. I really do not know what I have badly tested postman and everything works well. when trying to adapt with retrofit I only get null as a response. My class Utils public class ApiUtils { private ApiUtils() {} public static final String BASE_URL = "https://api.payulatam.com/"; public static APIService getAPIService() { return RetrofitClient.getClient(BASE_URL).create(APIService.class); } } My interface Class public interface

Null-pointer Exception, Retrofit?

对着背影说爱祢 提交于 2019-12-24 23:07:05
问题 I am trying to get an id from URL but getting the null pointer exception java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.hex.encode.ID_Model$User.id' on a null object reference at com.hex.encode.Home$3.onResponse(Home.java:99) and this is the code I am using to get the id: private void GetID() { Call<ID_Model> idcall = fetchdata.getIdService().getID(user_search); idcall.enqueue(new Callback<ID_Model>() { @Override public void onResponse(@NonNull Call<ID_Model>

Retrofit GET request with a parameter

久未见 提交于 2019-12-24 21:12:30
问题 I make a call to an api using Retrofit GET request. This GET request requires a parameter. The API works perfectly when i use POSTMAN for testing but when i try to use the API call below it returns Object reference not set to an instance of an object. @GET("/api/account/*******") Call<ResetPassword> requestPasswordResetToken(@Query("phoneNumber") String phoneNumber); And the code how i make that request in my activity. public void requestPasswordResetToken(String phoneNumber) { Retrofit

Android: library project with Retrofit results in NoClassDefFoundError

浪子不回头ぞ 提交于 2019-12-24 20:51:05
问题 I'm trying to build an android library project which uses OkHttp and Retrofit to grant access to our REST-backend. It seems to be working as long as I use api instead of implementation on my gradle-dependency for com.squareup.retrofit2:converter-gson . It seems that this is the only dependency needing this (all others can used with implementation ). When using implementation here as well, the calling app will crash with NoClassDefFoundError : java.lang.NoClassDefFoundError: Failed resolution

Send Json to server (nginx) as String - retrofit 2

懵懂的女人 提交于 2019-12-24 20:42:19
问题 I am connecting to web service with last version retrofit but get me bellow error : okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR Is this error okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL for huge string ? or for **nginx** of server ? My code is like bellow : try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @Override public void

Retrofit2:adapter-rxjava Certificate issue

ε祈祈猫儿з 提交于 2019-12-24 20:17:10
问题 I have the following dependencies in my android project: implementation 'com.squareup.retrofit2:converter-gson:2.1.0' implementation 'com.squareup.retrofit2:retrofit:2.2.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1' implementation 'com.squareup.okhttp3:okhttp:3.7.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.7' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' However, the 'com.squareup.retrofit2

Make a GET and POST service call with Retrofit with the use of Protobuf (Protocol Buffer)

走远了吗. 提交于 2019-12-24 17:22:42
问题 Can anyone please give me some example how we can use protobuf in retrofit - I tried but its failed with some error , let me give you a sample of my implementation on that. I hope you guys will help me. ApiInterface.java public interface ApiInterface { @GET Call<CommonProto.Country> makeGetRequest(@Url String url); } ApiClient.java public class ApiClient { public static final String BASE_URL = "**************************"; private static Retrofit retrofit = null; public static Retrofit

How to pass custom pojo as parameter to the interface method call in rxjava2 Observable?

半腔热情 提交于 2019-12-24 12:18:23
问题 Current code Observable.from(listMovie)//list of movie .flatMap(new Func1<Movie, Observable<FavMovieRes>>() { @Override public Observable<FavMovieRes> call(Movie movie) { return moviesAPI.makeMovieFav(userId), sessionId, new MakeMovieFav("movie", movie.getId(), movie.isFavList())); } }) .subscribe(new Subscriber<FavMovieRes>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(FavMovieRes favMovieRes) { } }); In above code I