我有一个使用Google Volley向Web服务器后端(http://www.example.com/request.php)发出请求的Android应用。用户移动地图时,将调用请求网页的代码。
问题是有时请求会失败。当失败时,我打开我的Chrome浏览器(也在手机上),然后导航到该“ request.php”后端页面。该请求失败,并显示连接超时错误。然后,我在Chrome中按刷新,它会正确加载。我重新打开我的应用程序,然后一切正常,即:请求通过。
我做了调试的步骤:
我从com.loopj异步库切换到Google Volley->仍然存在超时错误
移动地图时请求了其他页面(例如:stackoverflow.com而不是example.com/request.php)->没有错误
在服务器上的htaccess中添加了以下行:RewriteRule (.*) - [E=Cache-Control:no-cache]因为在使用x-litespeed-cache服务缓存的页面之前,我遇到问题->仍然存在超时错误
在多种设备和Android模拟器上进行过尝试->仍然随机存在超时错误
向我的虚拟主机提交了票证,询问他们是否注意到我页面上的任何超时错误-> 他们说不
这是我的代码:
public void updateMarkers() {
params = new HashMap<String, String>();
params.put("mykey", "myvalue");
StringRequest fpsr = new StringRequest(Method.POST, "http://www.example.com/request.php", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//do stuff with the response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//do stuff with error
}
}) {
@Override
protected Map<String, String> getParams() …Run Code Online (Sandbox Code Playgroud)