最近项目中 需要在网络结果返回时拿到请求的请求参数 所以通过询问和查询终于找到了实现的方法现在记录一下
返回的观察者结果需是Response类型
api.login1(userName.getText().toString(),passWord.getText().toString(),"test params").subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Response<JSONObject>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Response<JSONObject> jsonObjectResponse) {
RequestBody body = jsonObjectResponse.raw().request().body();
FormBody encoded = (FormBody) body;
System.out.println("Login1Activity.onNext " + jsonObjectResponse.raw().request().url() + " " + encoded.name(0) + " " + encoded.name(1) + " " + encoded.name(2) + " " + encoded.encodedValue(2));
JSONObject o = jsonObjectResponse.body();
boolean flag = false;
try {
if (o.getBoolean("Success")) {
flag = true;
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (flag) {
startActivity(MainActivity.class);
} else {
SnackbarUtil.showMessage(login,"登陆失败!","知道了");
}
}
}
});
通过把RequestBody 强转为FormBody 就能从里面拿到key value值了