• 1000 запрос от android устройства (эмулятора) с использованием библиотеки volley У меня постоянно возникала ошибка тайм-аута.
вот мой lumen / php код:
public function responseRequest(Request $request)
{
$response = Http::get($request->url);
$body = $response->body();
return response()->json([
'body' => $body,
'code' => 200
]);
}
Я использую android эмулятор и localhost.
и android код ниже:
public void getResponse(String url){
String apiUrl = "http://10.0.2.2:5000";
Map<String,String> params = new HashMap<>();
params.put("url", url);
JSONObject parameters = new JSONObject(params);
// dialog is defined in onCreate
dialog.setTitle("Loading");
dialog.setMessage("Loading, Please Wait");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.show();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, apiUrl, parameters, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
dialog.dismiss();
Log.d("APIResponse", "onResponse: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
dialog.dismiss();
if (error instanceof NetworkError) {
Toast.makeText(getApplicationContext(),
"Network Error",
Toast.LENGTH_LONG).show();
} else if (error instanceof ServerError) {
Toast.makeText(getApplicationContext(),
"Server Error",
Toast.LENGTH_LONG).show();
} else if (error instanceof ParseError) {
Toast.makeText(getApplicationContext(),
"Parsing Error",
Toast.LENGTH_LONG).show();
} else if (error instanceof NoConnectionError) {
Toast.makeText(getApplicationContext(),
"No Connection",
Toast.LENGTH_LONG).show();
} else if (error instanceof TimeoutError) {
Toast.makeText(getApplicationContext(),
"Oops. Timeout error!",
Toast.LENGTH_LONG).show();
}
}
});
Volley.newRequestQueue(this).add(jsonObjectRequest);
}