开发者社区> 问答> 正文

从 android 应用程序响应时间发送 php 查询到服务器

我想在数据库中放入一个entry。用的下面的代码:

String url = String.format("http://xxxxxxx/xxx/index.php?home=yes&pid=%s", pid);
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);
         Log.e("abc", response);
        return response;
        } catch (ClientProtocolException es) 
        {   
            Log.e("x" , es.getMessage());
            return "";
        } catch (IOException e) 
        {
            Log.e("aasx" , e.getMessage());
            return "";
        }

这段代码能正常运行,现在当有网络连接的时候,代码就会困在httpclient.execute(httppost, responseHandler); 大约俩分钟。
有什么方法可以实现检查几秒钟后,如果没有反应的就会就catch the exceptions?

展开
收起
小旋风柴进 2016-03-05 16:00:10 2525 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS块储存产品全面解析 立即下载