retrofit

javax.net.ssl.SSLException: Write error: ssl=0x7f70604080: I/O error during system call, Broken pipe

五迷三道 提交于 2019-12-21 04:39:17
问题 I use retrofit for uploading image to server, but have a strange issue api method declaration: @POST("/uploadImage") @Multipart Result<UploadImageResponse> uploadImage(@Part("image") TypedByteArray image); rest adapter user custom client: OkClient client = new OkClient(getUnsafeOkHttpClient()); where private OkHttpClient getUnsafeOkHttpClient() { try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{new

Serialize Query-Parameter in Retrofit

我们两清 提交于 2019-12-21 04:12:49
问题 Imagine the following request: @POST("/recipes/create") void createRecipe(@Query("recipe") Recipe recipe, Callback<String> callback); I would like to have toJson(recipe) but unfortunately my request is just calling toString() for my recipe which does not work at all. I could override the toString inside of Recipe but I'd rather have a general solution. I cannot use @Body as I need to specify, what I'm sending (i need to have "recipe=json(theRecipe)". I also cannot change the serialization to

Observer.onError firing off inconsistently

一世执手 提交于 2019-12-21 03:58:27
问题 I am using Retrofit to access my API as follows: public interface UserService { ... @POST("/user/login") public Observable<User> register(@Body() User user); } Here is how I access my API: mUserService.register(user) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<User>() { @Override public void onCompleted() { .... } @Override public void onError(Throwable e) { .... } @Override public void onNext(User user) { .... } }); This works

How to POST a bitmap to a server using Retrofit/Android

旧街凉风 提交于 2019-12-21 02:51:10
问题 I'm trying to post a bitmap to a server using Android and Retrofit . Currently I know how to post a file, but I'd prefer to send a bitmap directly. This is because the user can pick any image off their device. I'd like to resize it to save bandwidth before it gets sent to the server and preferrably not have to load it, resize it, save it as a file to local storage then post the file. Anyone know how to post a bitmap from Retrofit ? 回答1: NOTE: Make this conversion on other thread than Main.

java.lang.NumberFormatException: Expected an int but was 0.6 at line 1 column 8454

只谈情不闲聊 提交于 2019-12-20 20:35:14
问题 I'm using the retrofit library for my calls in a demo project. I received the following error: java.lang.NumberFormatException: Expected an int but was 0.6 at line 1 column 8454 path $.result.results.ads[2].acres I under stand that this is down to GSON. I will show you the JSON it's getting caught in: { "ad_id":739580087654, "property_type":"site", "house_type":"", "selling_type":"private-treaty", "price_type":"", "agreed":0, "priority":2, "description":"Beautiful elevated 0.6 acre site -

@DELETE method is not supporting(Non-body HTTP method cannot contain @Body or @TypedOutput.)

喜你入骨 提交于 2019-12-20 17:33:10
问题 @DELETE("/job/deletejob") Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model); am getting this error: Non-body HTTP method cannot contain @Body or @TypedOutput can any one help me to come out from this?? 回答1: I've used this official workaround recently: @HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true) Observable<JobDeleteResponseModel> jobDelete(@Body JobDeleteRequestModel model); 回答2: try this it's work @HTTP(method = "DELETE", path = "api/v3

Handling specific errors by sending another request transparently in retrofit

泪湿孤枕 提交于 2019-12-20 16:14:14
问题 Here's the case I'm trying to handle, If a request is executed, and the response indicates the auth token is expired, send a refresh token request if the refresh token request succeeds, retry the original request This should be transparent to the calling Activity, Fragment... etc. From the caller's point of view, it's one request, and one response. I've achieved this flow before when using OkHttpClient directly, but I don't know how to achieve this in Retrofit. Maybe something related to this

Gson deserializer with Retrofit converter: just need inner JSON for all responses

我与影子孤独终老i 提交于 2019-12-20 15:16:42
问题 I am working with an API that always responds like so: { "stuff_i_need": [ { "title": "Hello" }, { "title": "World!" } ], "status": "success" } and { "other_things_key": { "version": "208" }, "status": "success" } There are always two elements, and I just need the one that is not "status." I want to do this with one GsonBuilder, as well. I tried: new GsonConverter(new GsonBuilder() .registerTypeAdapter(List.class, new JsonDeserializer<List>() { @Override public List deserialize(JsonElement

Retrofit error URL query string must not have replace block

非 Y 不嫁゛ 提交于 2019-12-20 12:10:32
问题 I have this function @GET("/users?filters[0][field]={param}&filters[0][operator]=equals&filters[0][value]={value}") UserDto retrieveUsersByFilters(@Path("param") String nameFilter, @Path("value") String value); I try to call it like this : UserDto currentUser = interfaceUser.retrieveUsersByFilters(User.LOGIN, login); But i have error : retrofit.RetrofitError: InterfaceUser.retrieveUsersByFilters: URL query string "filters[0][field]={param}&filters[0][operator]=equals&filters[0][value]={value}

Retrofit 2.0 - How to get response body for 400 Bad Request error?

孤街醉人 提交于 2019-12-20 11:10:15
问题 So when I make a POST API call to my server, I get a 400 Bad Request error with JSON response. {  "userMessage": "Blah", "internalMessage": "Bad Request blah blah", "errorCode": 1 } I call it by Call.enqueue(new Callback<ResponseBody>() { @Override public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { //AA } @Override public void onFailure(Call<ResponseBody> call, Throwable t) { //BB } } However the problem is that once I get the response, onFailure() is invoke so