简体   繁体   中英

Retrofit 400 error

I'm making a call for a server like this:

   public void startModelFor(final AnotherModel anotherModel) {
    if (selectedConsumer == null) {
        getView().showNoConsumerError();
    } else {
        getView().setLoading();
        mApi.createModel(mManager.load(), selectedConsumer, ORDER_TYPE_TO_GO)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<MyModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        String str = e.getMessage();
                        Log.e("ERROR", "MESSSAGE: "+e.getMessage());
                        StringWriter writer = new StringWriter();
                        PrintWriter printWriter = new PrintWriter( writer );
                        e.printStackTrace( printWriter );
                        printWriter.flush();

                        String stackTrace = writer.toString();

                        //getView().showErrorOnCreateOrder();
                    }

                    @Override
                    public void onNext(MyModel model) {
                        getView().goToOrderMenu(anotherModel, model);
                    }
                });
    }
}

Just to populate a MyModel object. Every time a make a request I receive a 400 error message. The structure of MyModel object was not changed ie, any field of method was not added to the class. The called createModel method is a PUT call. Below is the stacktrace of the error.

retrofit.RetrofitError: 400 Bad Request
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)
at retrofit.RxSupport$2.run(RxSupport.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:841)

I can't get a hint to what is going on. I don't know if this occurs because data model on server is wrong this occurs at my side (client).

Try to use Postman app to test your HTTP request to the server and make sure, that your request is proper and you're getting right response. It's hard to tell where's the mistake on your side, because you haven't provided model of expected HTTP request (API documentation).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM