Android 如何从截取解析的http头请求中获取响应数据?
我使用basic64身份验证方法将用户名和密码传递给url。响应是一个令牌。如何使用volley库获取此令牌Android 如何从截取解析的http头请求中获取响应数据?,android,android-volley,Android,Android Volley,我使用basic64身份验证方法将用户名和密码传递给url。响应是一个令牌。如何使用volley库获取此令牌 提前感谢您可以使用以下代码传递JsonRequest JsonObjectRequest req = new JsonObjectRequest(Url, new JSONObject(), new com.android.volley.Response.Listener<JSONObject>() {
提前感谢您可以使用以下代码传递JsonRequest
JsonObjectRequest req = new JsonObjectRequest(Url, new JSONObject(),
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.v("Response:%n %s", response.toString(0));
JSONObject jsonObject = new JSONObject(response.toString());
String success = jsonObject.getString("success");
// Get your Token Here.
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(LoginActivity.this, "Server or Connection Error.", Toast.LENGTH_SHORT).show();
builder.dismiss();
}
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(req);
我想你会在这里找到解决办法的希望这对你有帮助对不起,但那没有帮助。。im使用解析的网络类@Override public Map getHeaders抛出AuthFailureError传递请求{Map headers=new HashMap;//添加头字符串凭据=email+:+密码;字符串auth=Basic+Base64.encodeToStringcredentials.getBytes,Base64.NO_WRAP;headers.putAuthorization,auth;返回头;}尝试使用常用方法获取响应..但给出未知响应..响应数据:[B@41a24780调用response.statuscode时,我获取的状态代码正确。但调用response.data时,我获取的响应未知ResponseResponseA:[B@41a24780
public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance(){
return mInstance;
}
public RequestQueue getRequestQueue(){
if(mRequestQueue == null){
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}