Bitte, fügt Volley automatisch meine GET-Parameter zur URL hinzu? Für mich funktioniert es nicht so und auch wenn ich nach Quellen suche, finde ich keinen Aufruf der getParams Methode. Also sollte ich die URL selbst erstellen? Es ist kein Problem, ich dachte nur, dass, wenn es ein solches Verfahren wie getParams ist, ist es das für mich tun könnte :)Volley ruft getParams nicht für meine benutzerdefinierte Anfrage auf?
UPDATE: Unten ist mein 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);
}
}
Tatsächlich ist die params Parameter ist nun überflüssig
danke..ich denke, ich sollte versuchen, javadoc zu lesen :) – simekadam
gibt es einen bestimmten Grund, warum getPrams() nicht auf GET aufgerufen wird? – ANinJa