使用xutils3进行网络请求,post需要传参报错: Unsupported Media Type 经核实,之前是这样传参,报错
2022-04-20 11:56:05.081 27544-27544/com.ruhai.yibei E/wy: onCreate params: https:
2022-04-20 11:56:05.145 27544-27544/com.ruhai.yibei E/wy: 102 result: Unsupported Media Type
RequestParams params = new RequestParams(Constant.getTraderId);
params.addHeader("Authorization", Constant.authorization);
params.addHeader("language", "zh_CN");
params.addBodyParameter("key","a0a37c9795114beb830aa5e1afb77eb");
x.http().post(params, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
Log.e("wy", "145getUseSig: " + result);
TraderIdBean userSignBean = JSON.parseObject(result, TraderIdBean.class);
Log.e("wy", "147: " + userSignBean.getData().getTraderId());
if (userSignBean.getCode() == "00000000") {
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
Log.e("wy", "102 result: " + ex.getMessage());
}
@Override
public void onCancelled(CancelledException cex) {
Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
}
@Override
public void onFinished() {
}
});
现在是这样传参,成功;非得搞一个Bean实体类才行,真是奇怪
2022-04-20 11:55:16.594 25587-25587/com.ruhai.yibei E/wy: onCreate params: https:
2022-04-20 11:55:16.670 25587-25587/com.ruhai.yibei E/wy: 145getUseSig: {"msg":"success","code":"00000000","data":{"traderId":100,"key":"d9db4d26504b4fb5b5cc2fb2fc272371"}}
KeyBean keyBean = new KeyBean();
String keyBeanString = JSON.toJSONString(keyBean);
RequestParams params = new RequestParams(Constant.getTraderId);
params.addHeader("Authorization", Constant.authorization);
params.addHeader("language", "zh_CN");
params.addBodyParameter("", keyBeanString);
x.http().post(params, new Callback.CommonCallback<String>() {
@Override
public void onSuccess(String result) {
Log.e("wy", "145getUseSig: " + result);
TraderIdBean userSignBean = JSON.parseObject(result, TraderIdBean.class);
Log.e("wy", "147: " + userSignBean.getData().getTraderId());
if (userSignBean.getCode() == "00000000") {
}
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
Log.e("wy", "102 result: " + ex.getMessage());
}
@Override
public void onCancelled(CancelledException cex) {
Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
}
@Override
public void onFinished() {
}
});
总结:直接是键值对, 不是json形式
|