无法在Android中使用改装获得响应

时间:2018-09-04 11:37:53

标签: android retrofit

https://api.tj.com/orderNumber/order

请求参数表:

Header 
Authorization: Beer naskjnkjnsadsad
Content-Type:application/json

Body json:

{
  "orderRequestId" : "890329jnfndlsd",
  "stateOfOldOrder" : "NotComplted"
}

响应:

raw response : HTTP/1.1 204 No Content
Date: Fri, 31 Aug 2018 09:39:47 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 0
ID: jhdsahjksa219212
Connection: keep-alive

响应应该出现在标题中 这是我的例外输出,在Postman中工作正常

但是在使用改造时,我正在尝试这段代码

@POST("orderNumber/order") 
Observable<ResponseBody> requestOrderCard(@Body OrderRequest request);

并这样调用:

orderService.requestOrderCard(request)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.computation())
                .map(voidResponse -> {
                    Log.d("RESPONSEsss","vodiresponse");
                    return voidResponse;
                })

                .subscribe(voidResponse -> {
                            Log.d("RESPONSEsss","vodiresponse");
                        },
                        error -> {
                            Log.d("ERRRROOOR","Error");
                        });

但是每次我遇到错误时,请建议我如何在android改造中的Post方法中没有Content Only Header的情况下获得响应。

1 个答案:

答案 0 :(得分:0)

使用单个而不是可观察的

listSingle.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new SingleObserver<Response<OBJECT>>() {
                        @Override
                        public void onSubscribe(Disposable d) {

                        }

                        @Override
                        public void onSuccess(Response<OBJECT> objectdto) {
                            if (objectdto.code() == 200 && objectdto.body() != null) {
                                getMvpView().sucess(objectdto.body());
                            } else if (objectdto.errorBody() != null) {
                                getMvpView().setErrorMessage(objectdto.errorBody());
                            } 
                        }

                        @Override
                        public void onError(Throwable e) {
                            getMvpView().setErrorMessage("Something went Wrong");
                        }
                    });

像这样检索

OBJECT.java

private class OBJECT{
{
  private String orderRequestId;
  private String stateOfOldOrder;

}

您的对象将是

aaptOptions