Tag: retrofit2

获取正文从错误响应中使用execute()进行Retrofit

所以出于某种原因,我需要像这样执行我的电话: val result = manager.call.execute() if (result.isSuccess) { //do stuff } else { //handle exeption } 当我的代码到达else括号result.body()为空, result.errorBody()的缓冲区内容为0,但不是它的长度。 但是,这是我从改造的日志: <– 400 Bad Request https://cubus-friends- … D/OkHttp: {"error":"validation_error","error_description":"No user with that phone number"} D/OkHttp: <– END HTTP (81-byte body) 我怎样才能让我的json错误字符串到我的代码中的else括号?

通过Retrofit 2上传图像时是否可以显示进度条?

我目前正在使用Retrofit 2 ,我想在我的服务器上传一些照片。 我知道,旧版本使用TypedFile类来上传。 如果我们想使用进度条,我们应该重写TypedFile类中的writeTo方法。 使用retrofit 2库时可以显示进度吗?

Android Retrofit + Google Places API(文本搜索)

我正在尝试根据给定的查询来获取地点。 我实现了以下接口。 @GET("api/place/textsearch/json?key=MY_API_KEY") Call<PlaceResponse> getNearbyPlacesByText(@Query("query") String query, @Query("location") String location, @Query("radius") int radius); 然后我这样调用这个方法 Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .addConverterFactory(GsonConverterFactory.create()) .build(); ApiInterface service = retrofit.create(ApiInterface.class); Call<PlaceResponse> callByText = service.getNearbyPlacesByText("psí" + "škola", currentLocation.getLatitude() + "," + currentLocation.getLongitude(), PROXIMITY_RADIUS); 然后我正在检索结果。 callByText.enqueue(new Callback<PlaceResponse>() { @Override public void onResponse(Call<PlaceResponse> call, Response<PlaceResponse> response) { List<Place> places = response.body().getResults(); Log.d(TAG, […]

android翻新2图片上传

我的api http://192.168.0.2/littlezebra/scripts/webservice.php?Case=updateProfile&user_id=1&profile_picture=happychild.png 如何在@Query发送这个

如何使用Kotlin,翻新和RXjava来填充列表视图

我与服务的整合已经准备就绪,我可以在请求日志中看到我的数组,但是我无法填充列表视图。 我真的已经尝试了我所知道的一切,我对kotlin是新的,语言让我有点困惑。 有人可以找出错误的地方,我做错了。 JSON /请求: {"0":{"id":1,"nome":"teste"},"1":{"id":2,"nome":"teste 2"}} apiClient.kt val service : ApiInterface val URL = "json" init { val logging = HttpLoggingInterceptor() logging.level = HttpLoggingInterceptor.Level.BODY val httpClient = OkHttpClient.Builder() httpClient.addInterceptor(logging) val gson = GsonBuilder().setLenient().create() val retrofit = Retrofit.Builder() .baseUrl(URL) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .client(httpClient.build()) .build() service = retrofit.create<ApiInterface>(ApiInterface::class.java) } ApiInterface.kt @Headers("Accept: application/json") @GET("/request") fun getInstituicoes(): Observable<Instituicao> Instituicao.kt(实体) […]