小编ste*_*fan的帖子

Crest ErrorHandler获取响应数据

我们正在开发一个Android应用程序,我们想要使用crest lib.我们正在使用的Web服务在某些情况下400返回错误请求以及json格式的其他响应数据.我们有成功的响应处理程序和坏请求的错误处理程序.是否可以在错误处理程序中获取返回的数据?

错误处理程序

public class RestErrorHandler implements ErrorHandler{

@Override
public <T> T handle(Request request, Exception e) throws Exception {

    // here we need to check the code returned from the 
    // web service in case of a bad request
    return null;
}

}
Run Code Online (Sandbox Code Playgroud)

坏请求看起来像这样:

HTTP/1.1 400 Bad Request
Content-Length: 59
Date: Wed, 08 Feb 2012 15:01:23 GMT
Server: Apache
Set-Cookie: session=A…...
Status: 400
Vary: Accept-Encoding
Connection: close
Content-Type: application/json
{"status":false,"code":"403","message":"wrong credentials"}
Run Code Online (Sandbox Code Playgroud)

java rest android

0
推荐指数
1
解决办法
264
查看次数

标签 统计

android ×1

java ×1

rest ×1