roid的HttpClient的使用GET请求只是将数据发送到服

roid的HttpClient的使用GET请求只是将数据发送到服

本文介绍了Android的HttpClient的使用GET请求只是将数据发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问一个参数化URL与Android。它所需要做的就是负荷的页​​面,以便它做什么,它应该做的(带参数更新数据库中给出)。

I want to access a parameterized url with Android. All it has to do is "load" the page so that it does what its supposed to do (update database with parameters given).

我遇到了麻烦只是加载的URL所以我看了定期HttpClient的活动视频 - 只是在等待响应和收集信息。我想,它仍然会加载页面,因此也让该页面执行。我甚至不能得到正常运行的页面或收集的响应。

I was having trouble just loading the url so I watched a video on regular HttpClient activity -- just waiting for the response and gathering that information. I figured that it would still be loading the page and therefore also letting that page execute. I can't even get that to run the page correctly or gather a response.

这里的code我用:

String url = "http://www.removed.com?param1="+param1+"&param2="+param2;

        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            InputStream webs = entity.getContent();
            try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(webs, "iso-8859-1"), 8 );
                test.setText(reader.readLine());
                webs.close();
            }catch(Exception e) {
                Log.e("Error in conversion: ", e.toString());
            }
        }catch(Exception e) {
            Log.e("Error in connection: ", e.toString());
        }

请让我知道我能做些什么来得到这个执行该页面,并更新数据库。如果我把这些参数手动到浏览器中,它的工作原理。

Please let me know what I can do to get this to execute the page and update the database. If I put in the parameters manually into a browser, it works.

推荐答案

您还没有张贴在你运行这个还是什么错误,但浮现在脑海中的第一个两件事情是:

You haven't posted where you're running this or what the error is, but the first two things that come to mind are:


  • 请您在清单将Internet的权限?

  • 如果这是蜂窝,这是在一个单独的线程中运行? - 由于3.0不能运行在主线程显示HTTP请求

这篇关于Android的HttpClient的使用GET请求只是将数据发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:51