gpt4 book ai didi

android - Volley 库使服务器无响应

转载 作者:行者123 更新时间:2023-11-29 01:04:12 27 4
gpt4 key购买 nike

我是 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 请求发送数据。

最佳答案

您需要像这样更改请求参数键..

@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;
}

关于android - Volley 库使服务器无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48742511/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com