我在运行此代码时遇到了Android Volley的问题,我在Android 5.0.1版本上测试了它是否正常工作,但是在Android版本6.0.1上它存在
错误: E/凌空 (22302(: [15348] 基本网络.执行请求:
https://site/OutletService.asmx/update_outlet 的意外响应代码 500
你对此有什么想法吗?非常感谢您的帮助。
Map<String, String> map = new HashMap<String, String>();
map.put(Constant.User.AccessKey, accessKey);
JSONArray jsonArray = new JSONArray();
jsonArray.put(toJSONObject());
map.put("Content-Type", "text/html; charset=utf-8");
//map.put(Constant.ListOutlet, String.valueOf(toJSONObject()));
map.put(Constant.ListOutlet, jsonArray.toString());
Log.i("SubmitData", map.toString());
ServerStringPostRequest submitRequest = new ServerStringPostRequest(map, ip + Constant.prefixtServerUpdateOutlet, new Listener<String>() {
@Override
public void onResponse(String responses) {
Log.i("Update", responses);
try {
JSONObject response = new JSONObject(responses);
String code = response.getString(Constant.code);
if (code.equals("1")) {
uploadImageForOutlet(context, ip, accessKey, callBack);
// callBack.onSuccess(OutLet.this);
} else if (code.equals("0")) {
callBack.onFail(OutLet.this);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
如果您仅在Android 6中遇到问题。 那么似乎是应用程序中运行时权限的问题。因此,在运行时在java代码(活动(中添加所有清单权限,如下所示:
This is only for sample
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.INTERNET)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.INTERNET},
MY_PERMISSIONS_REQUEST_INTERNET);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
有关完整的参考,请参阅这些链接
链接 1
链接2