使用API​​进行改造在API 22上运行良好,但它在API 18上给出了错误400

时间:2017-08-23 17:29:52

标签: android

我的代码如下所示:

 private void SearchItems(String searchText) {
        if (InternetConnection.checkConnection(this)) {
            Observable<GenericResponse<List<FoodTruck>>> searchItems = RetroClient.getApiService()
                    .searchItems("Bearer " + SessionManager.get(SearchActivity.this).getAuthToken(), searchText.trim());
            searchItems.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<GenericResponse<List<FoodTruck>>>() {
                        @Override
                        public void onCompleted() {
                            unsubscribe();
                        }

                        @Override
                        public void onError(Throwable e) {
                            Toast.makeText(SearchActivity.this,e.getMessage(),Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onNext(GenericResponse<List<FoodTruck>> response) {
                            foodTruckList.clear();
                            foodtruckInfoList.clear();
                            foodTruckList.addAll(response.getData());
                            for (FoodTruck foodTruck : foodTruckList) {
                                for (FoodTruckItem foodTruckItem : foodTruck.getFoodTruckItemList()) {
                                    FoodtruckInfo foodtruckInfo = new FoodtruckInfo();
                                    foodtruckInfo.setFoodTruckName(foodTruck.getFoodTruckName());
                                    foodtruckInfo.setFoodTruckImage(foodTruck.getFoodTruckLogo());
                                    foodtruckInfo.setFoodTruckId(foodTruck.getFoodTruckId());
                                    foodtruckInfo.setOrderStatus(foodTruck.getFoodTruckOpenStatus());
                                    foodtruckInfo.setItemName(foodTruckItem.getItemName());
                                    foodtruckInfo.setItemId(foodTruckItem.getItemId());
                                    foodtruckInfo.setRating(foodTruck.getFoodTruckRating());
                                    foodtruckInfo.setItemCategory(foodTruckItem.getItemCategory());
                                    foodtruckInfoList.add(foodtruckInfo);
                                }
                            }
                            searchInfoAdapter.notifyDataSetChanged();
//                            searchInfoAdapter.addSearchItems(response.getData());
                        }
                    });
        } else {
            Toast.makeText(SearchActivity.this, R.string.string_internet_connection_warning, Toast.LENGTH_SHORT).show();
        }
    }

我正在使用此网址http://ec2.com/items/search?item_name=sala。此请求适用于API 22,但不适用于API 18,它为我提供HTTP 400 Bad Request。我不知道为什么相同的代码不适用于API 18。

0 个答案:

没有答案