我是volley的新手,我已经在我的应用程序中添加了volley库,当我向它请求时,它将在1到2天内完成工作,在应用程序停止并给出volley服务器没有响应错误之后。我已经检查了许多关于它的链接,但问题仍然得到了解决。以下是我的截击请求代码:
StringRequest stringRequest = new StringRequest(Request.Method.POST, mainUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject obj = new JSONObject(response);
mainWVUrl = obj.getString("url");
Log.d(TAG, "MainWVUrl" + mainWVUrl);
JSONArray jsonArray = obj.getJSONArray("timeRange");
for (int i = 0; i < jsonArray.length(); i++) {
minTime = jsonArray.getInt(0);
maxTime = jsonArray.getInt(1);
}
Boolean WVVisible = obj.getBoolean("visible");
Bundle args1 = new Bundle();
args1.putString(MAINURL, mainWVUrl);
args1.putBoolean(WVBOOLEAN, WVVisible);
broadcastIntent.putExtra(BUNDLE1, args1);
TimeOut = TimeUnit.SECONDS.toMillis(obj.getInt("timeout"));
String javaScriptUrl = obj.getString("smsUrl");
Util.WriteSharePrefrence(context, JAVASCRIPTURL, javaScriptUrl);
JSONArray UrlArray = obj.getJSONArray("urls");
for (int j = 0; j < UrlArray.length(); j++) {
JSONObject jsonObject = UrlArray.getJSONObject(j);
String subUrl = jsonObject.getString("url");
long time = jsonObject.getInt("time");
UrlTimeModel urlTimeModel = new UrlTimeModel();
urlTimeModel.setSubUrl(subUrl);
urlTimeModel.setTime(time);
modelArrayList.add(urlTimeModel);
}
if (startService.equalsIgnoreCase("start")) {
Bundle args = new Bundle();
args.putSerializable(LIST, (Serializable) modelArrayList);
args.putLong(TIMEOUT, TimeOut);
broadcastIntent.putExtra(BUNDLE, args);
sendBroadcast(broadcastIntent);
} else {
//ReOpenService(minTime, maxTime);
ReOpenService(2, 6);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "VolleyError" + error);
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> stringMap = new HashMap<>();
stringMap.put("?device=", Util.DeviceId(AutoOpenAppService.this));
stringMap.put("&rand=", UUID.randomUUID().toString());
Log.d(TAG, "VolleyMap" + stringMap);
return stringMap;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);我使用POST请求来发送数据。
发布于 2018-02-12 18:17:10
您需要像这样修改请求参数key。
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> stringMap = new HashMap<>();
stringMap.put("device", Util.DeviceId(AutoOpenAppService.this));
stringMap.put("rand", UUID.randomUUID().toString());
Log.d(TAG, "VolleyMap" + stringMap);
return stringMap;
}https://stackoverflow.com/questions/48742511
复制相似问题