HTTPGET是不工作的查询字符串 [英] httpget is not working for query string

查看:200
本文介绍了HTTPGET是不工作的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作获得通过查询字符串数据。我这样做有httppost但不是我特林开始使用HTTPGET。但我不能。

i am working to get data by query string . i have done with httppost but not i am tring to get using httpget . but i am unable.

 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("key", "android developer"));

            String k = "android developer";
             URI uri = new URI("http://10.0.2.2:8080/r/r.php");


             HttpClient httpclient = new DefaultHttpClient();
             HttpGet httpget = new HttpGet(uri);
             //httpget.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             HttpResponse response = httpclient.execute(httpget);
             HttpEntity entity = response.getEntity();
             is = entity.getContent();

请高手帮我

推荐答案

您可以通过两种方式做到这一点:

You can do this via 2 ways:

使用URI生成器:

new Uri.Builder()
    .scheme("http")
    .authority("foo.com")
    .path("someservlet")
    .appendQueryParameter("param1", foo)
    .appendQueryParameter("param2", bar)
    .build();

创建URL字符串自己:

String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
uri = new Uri("http://10.0.2.2:8080/r/r.php?" + paramString);

这篇关于HTTPGET是不工作的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆