排球并不要求getParams能够为我的定制要求?我的、并不、排球、getParams

由网友(最美的时光遇见了你)分享简介:请,不乱射自动添加我的GET参数的URL?对我来说,这不是工作,所以,也寻找到源时,我只是不能找到getParams能够方法的任何调用..所以,我应该建立自己的网址?这是一点问题都没有,我只是觉得,当有这样的方法就像getParams能够,它可以为我做的:)Please, does Volley automatic...

请,不乱射自动添加我的GET参数的URL?对我来说,这不是工作,所以,也寻找到源时,我只是不能找到getParams能够方法的任何调用.. 所以,我应该建立自己的网址?这是一点问题都没有,我只是觉得,当有这样的方法就像getParams能够,它可以为我做的:)

Please, does Volley automatically add my GET params to the URL? For me it's not working so and also when looking into sources, I just cant find any call of the getParams method.. So should I build the URL myself? It's no problem at all, I just thought that when there is such method like getParams, it could do that for me:)

更新:下面是我的code ..

UPDATE: Below is my code..

public class BundleRequest extends com.android.volley.Request<Bundle>{

    private String token;
    private OnAuthTokenValidatorResponseListener mListener;
    private final Map<String, String> mParams =  new HashMap<String, String>();;


    public BundleRequest(int method, String url,  Response.ErrorListener listener) {
        super(method, url, listener);
    }

    public BundleRequest(int method, String url,OnAuthTokenValidatorResponseListener providedListener,  Response.ErrorListener listener, String token) {
        super(method, url, listener);
        this.token = token;
        mListener = providedListener;
        mParams.put(AuthenticatorConfig.TOKEN_VALIDATION_PARAMNAME, token);

    }

    @Override
    public Map<String, String> getParams() throws AuthFailureError {
        return mParams;
    }




    @Override
    protected Response<Bundle> parseNetworkResponse(NetworkResponse httpResponse) {
        switch (httpResponse.statusCode) {
            case AuthTokenValidator.TOKEN_VALID_RESPONSE_CODE:
                //token is ok
                JSONObject response;
                try {
                        response = new JSONObject(new String(httpResponse.data, HttpHeaderParser.parseCharset(httpResponse.headers)));
                        Bundle userDataResponse = new Bundle();
                        userDataResponse.putInt("responseCode", httpResponse.statusCode);
                        userDataResponse.putString("username", response.getString("user_id"));
                        userDataResponse.putString("email", response.getString("user_email"));
                        userDataResponse.putString("expiresIn", response.getString("expires_in"));
                        userDataResponse.putString("scope", response.getJSONArray("scope").getString(0));
                        userDataResponse.putString("token", token);
                    return Response.success(userDataResponse, HttpHeaderParser.parseCacheHeaders(httpResponse));
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    return Response.error(new VolleyError("Unsupported encoding"));


                } catch (JSONException e) {
                    e.printStackTrace();
                    return Response.error(new VolleyError("Problem while parsing JSON"));
                }




            case AuthTokenValidator.TOKEN_INVALID_RESPONSE_CODE:
                //token is not valid
                mListener.onValidatorResponse(httpResponse.statusCode);
                try {
                    mListener.onValidatorResponse(parseOnErrorResponse(new String(httpResponse.data, HttpHeaderParser.parseCharset(httpResponse.headers))));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }

            default:
                return Response.error(new VolleyError("Error status code:" + httpResponse.statusCode));

        }
    }

    protected int parseOnErrorResponse(String responseBody) {
        try {
            JSONObject response = new JSONObject(responseBody);
            String moreInfo = response.getString("more_info");
            if (moreInfo.equals("Token was not recognised")) {
                return AuthTokenValidator.TOKEN_WAS_NOT_RECOGNISED;
            } else if (moreInfo.equals("Token has expired")) {
                return AuthTokenValidator.TOKEN_HAS_EXPIRED;
            } else if (moreInfo.equals("Client doesn't exist anymore")) {
                return AuthTokenValidator.CLIENT_DOES_NOT_EXIST_ANYMORE;
            } else if (moreInfo.equals("Client is locked")) {
                return AuthTokenValidator.CLIENT_IS_LOCKED;
            } else {
                return AuthTokenValidator.UNKNOWN_ERROR;
            }

        } catch (JSONException e) {
            e.printStackTrace();
            return AuthTokenValidator.UNKNOWN_ERROR;
        }

    }

    @Override
    protected void deliverResponse(Bundle response) {
        mListener.onGetUserDataResponse(response);
    }
}

其实PARAMS参数现在是多余的。

Actually the params parameter is now redundant

推荐答案

getParams()方法不叫上GET方法,这样看来,你必须增加它的URL,然后发送请求。

getParams() is not called on the GET method, so it seems you'll have to add it to the URL before you send the request.

退房JavaDoc的:

Check out the JavaDoc:

返回地图的参数要用于一个POST或PUT请求。

Returns a Map of parameters to be used for a POST or PUT request.

可以抛出{@link AuthFailureError}身份验证可能需要   提供这些值。

Can throw {@link AuthFailureError} as authentication may be required to provide these values.

请注意,您可以直接覆盖{@link #getBody()}定制   数据。

Note that you can directly override {@link #getBody()} for custom data.

@throws AuthFailureError在权威性故障的情况

@throws AuthFailureError in the event of auth failure

阅读全文

相关推荐

最新文章