Android的HTTP GET参数

编程入门 行业动态 更新时间:2024-10-10 03:24:14
本文介绍了Android的HTTP GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的Apache HTTP库,并需要知道如何将一个参数添加到HTTP GET请求。我看过了How将参数添加到Android的一个HTTP GET请求?但是对于接受的答案将参数的HTTP POST。这是我的code,到目前为止,但它不能正常工作。

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

解决方案

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

myurl?variable1=value&variable2=value2

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

启动

请参阅这里更多的信息。

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

编辑:

在你的情况:

HTTPGET的get =新HTTPGET(server/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("server/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:

myurl?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("server/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参数

本文发布于:2023-11-25 10:22:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Android   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!