我有一个本机 Android 应用程序,使用 volley 框架从PHP
服务器端脚本。
它在大多数情况下都运行良好,但我有 20% 的失败率。
错误说:
com.android.volley.NoConnection,java.io.InterruptedIOException。
我调试了一下发现statuscode = 0
,这显然是错误的。
我不知道原因是什么?由于它大部分时间都在工作,所以不应该有明显的错误代码。
仅供参考,服务器端的那些 PHP 脚本非常适合我的 IOS 应用程序。
请允许我在这里发布我的代码:
retryConnBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
txtOut.append("\n");
txtOut.append("Button with Retry Click");
Log.d("Click", "Button Click");
final String url = "https://www.myserver.com/api/getBalanceInfoTest?token=7ff3317a4f3dc07d0c297a7d16d2049c&t=" + System.currentTimeMillis();
//final String url = "http://192.168.1.23/base/test/";
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
txtOut.append("\n");
txtOut.append("Result with Retry:");
txtOut.append(response.toString());
Log.d("Response", response.toString());
VolleyLog.e("Response:", response.toString());
}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
txtOut.append("\n");
txtOut.append("Error with Retry:");
txtOut.append(error.toString());
Log.d("Error.Response", error.toString());
VolleyLog.e("Error:", error.getMessage());
}
});
getRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(getRequest);
queue.start();
}
});
}
有关更多信息,我的输出PHP
脚本是:{"hsaBalance":"1000.00"}
, 由...制作Json_encode()
的函数PHP
.