我在我的应用程序中对超过 10 种不同的连接类型使用相同类型的请求,除了这个之外,它们都可以工作,我不知道为什么,它们之间的唯一区别是发送的参数。如果我手动发送请求(通过在 URL 栏中输入数据),一切都会恢复正常,但是当 volley 尝试连接时,它说NoConnectionError
正在发生。我用我的 4G 连接和 WIFI 连接试过这个,它总是返回相同的。
更新
好的,所以我在发送纬度/经度时取出了参数,现在服务器发送回响应。我发送的纬度/经度错误吗?
public void updateLoc(final double latitude, final double longitude, final Context context)
{
if (context != null)
{
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_FOR_ACCOUNT,
new Response.Listener<String>() {
@Override
public void onResponse(String response)
{
Log.e("Network", "Response " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof TimeoutError) {
Log.e(TAG,"Update Location Request timed out.");
}else if (error instanceof NoConnectionError){
Log.e(TAG,"Update Location no connection.");
} else if (error instanceof AuthFailureError) {
Log.e(TAG,"Auth failure");
} else if (error instanceof ServerError) {
Log.e(TAG,"Server Error");
} else if (error instanceof NetworkError) {
Log.e(TAG,"Network Error");
} else if (error instanceof ParseError) {
Log.e(TAG,"Parse Error");
}
}
}) {
//adding parameters to the request
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("command", "updateLoc");
params.put("appVersion", version);
params.put("androidVersionNumber", Integer.toString(Build.VERSION.SDK_INT));
params.put("email", userEmail);
params.put("lat", String.valueOf(latitude));
params.put("long", String.valueOf(longitude));
return params;
}
};