Android的HTTP GET参数 [英] Android HTTP GET parameters

查看:222
本文介绍了Android的HTTP GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Apache HTTP库,并需要知道如何将一个参数添加到HTTP GET请求。我看过了<一href="http://stackoverflow.com/questions/2959316/how-to-add-parameters-to-a-http-get-request-in-android">How将参数添加到Android的一个HTTP GET请求?但是对于接受的答案将参数的HTTP POST。这是我的code,到目前为止,但它不能正常工作。

  HTTPGET的get =新HTTPGET(https://server.com/stuff);
名单&LT;的NameValuePair&GT; namevaluepairs中=新的ArrayList&LT;的NameValuePair&GT;();
nameValuePairs.add(新BasicNameValuePair(计数,5));
的HttpParams p值= get.getParams();
p.setParameter(长度,5);
get.setParams(对);
 

解决方案

不像POST,GET发送的网址是这样下的参数:

  http://myurl.com?variable1=value&variable2=value2
 

其中:参数区域的问号和这样的变量1 的是第一个参数,它有的价值...

启动

请参阅这里更多的信息。

所以,你需要做的就是构建一个包含也可根据服务器需要这些参数的URL。

编辑:

在你的情况:

  HTTPGET的get =新HTTPGET(https://server.com/stuff?count=5&length=5);
...
 

其中:?计数= 5和长度= 5是参数和标志是参数定义的开头... 我希望帮助。

I'm using the apache http library and need to know how to add a parameter to an HTTP GET request. I've looked over How to add parameters to a HTTP GET request in Android? but the accepted answer for that adds parameters to an HTTP POST. This is my code so far but it is not working.

HttpGet get = new HttpGet("https://server.com/stuff");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("count", "5"));
HttpParams p = get.getParams();
p.setParameter("length", "5");
get.setParams(p);

解决方案

unlike POST, GET sends the parameters under the url like this:

http://myurl.com?variable1=value&variable2=value2

Where: the parameters area start from the question mark and on so the variable1 is the first param and it has "value" value...

See here for more informations.

So what you need to do is just build an url that contains also these parameters according to server needs.

EDIT:

In your case :

HttpGet get = new HttpGet("https://server.com/stuff?count=5&length=5");
...

Where: count=5 and length=5 are the parameters and the "?" mark is the beginning of the parameters definition... I hope that helps.

这篇关于Android的HTTP GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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