为什么排球onErroResponse如此无用?

时间:2014-09-15 20:05:25

标签: android android-volley

为什么Volleys errorResponse如此无用?

它几乎没有提供任何信息? Bellow是它为我提供的VolleyError对象的屏幕截图。

enter image description here

它真的告诉我什么?我可以解释原因和详细信息直到我变蓝。

AM我只是遗漏了一些东西,还是有另一个地方可以找出请求失败的原因?

因为现在告诉我ServerError没什么帮助。

[编辑]

这是我拨打电话的代码:

public void Login(String mEmail, String mPassword) {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("grant_type", "password");
    params.put("username", "user@email.co.za");
    params.put("password", "123456");
    params.put("client_id","ManagementInterface");

     HashMap<String, String> headers = new HashMap<String, String>();
     headers.put("Accept", "application/json");
     headers.put("Content-Type", "application/x-www-form-urlencoded");  

    GsonRequest<JsonObject> tokenRequest = new GsonRequest<JsonObject>(
            Request.Method.POST, "token", JsonObject.class, headers,
            params, new Response.Listener<JsonObject>() {
                @Override
                public void onResponse(JsonObject response) {
                    String Token = "";
                    onOkResponseHandle(Token);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    onErrorResponseHandle(error);
                }
            }); 

    Network.getInstance(this).addToRequestQueue(tokenRequest);
}

我正在尝试使用volley复制此请求: Image***

GSONRequest类:

 public class GsonRequest<T> extends Request<T> {
private final Gson gson = new Gson();
private final Class<T> clazz;
private final Map<String, String> headers;
private final Map<String, String> params;
private final Listener<T> listener;

/**
 * Make a GET request and return a parsed object from JSON.
 * 
 * @param url
 *            URL of the request to make
 * @param clazz
 *            Relevant class object, for Gson's reflection
 * @param headers
 *            Map of request headers
 */
public GsonRequest(int method, String url, Class<T> clazz,
        Map<String, String> headers, Map<String, String> params,
        Listener<T> listener, ErrorListener errorListener) {
    super(method, Network.getFullUrl(url), errorListener);
    this.clazz = clazz;
    this.headers = headers;
    this.params = params;
    this.listener = listener;
}

/**
 * Recieves header
 * 
 * @param method
 * @param url
 * @param clazz
 * @param params
 * @param listener
 * @param errorListener
 */
public GsonRequest(int method, String url, Class<T> clazz,
        Map<String, String> params, Listener<T> listener,
        ErrorListener errorListener) {
    super(method, Network.getFullUrl(url), errorListener);
    this.clazz = clazz;
    this.headers = new HashMap<String, String>();
    this.params = params;
    this.listener = listener;
}

/**
 * No params or headers
 * 
 * @param method
 * @param url
 * @param clazz
 * @param listener
 * @param errorListener
 */
public GsonRequest(int method, String url, Class<T> clazz,
        Listener<T> listener, ErrorListener errorListener) {
    super(method, Network.getFullUrl(url), errorListener);
    this.clazz = clazz;
    this.headers = new HashMap<String, String>();
    this.params = new HashMap<String, String>();
    this.listener = listener;
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    return headers != null ? headers : super.getHeaders();
}

@Override
public Map<String, String> getParams() throws AuthFailureError {
    return params != null ? params : super.getParams();
}

    @Override
protected void deliverResponse(T response) {
    listener.onResponse(response);
}

@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        String json = new String(response.data,
                HttpHeaderParser.parseCharset(response.headers));
        return Response.success(gson.fromJson(json, clazz),
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JsonSyntaxException e) {
        return Response.error(new ParseError(e));
    }
}

}

0 个答案:

没有答案