发送阵列与一个HTTP GET [英] Send an Array with an HTTP Get

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

问题描述

如何发送一个HTTP数组Get请求?

How can i send an Array with a HTTP Get request?

我使用GWT客户端发送请求。

I'm Using GWT client to send the request.

推荐答案

这要看什么目标服务器接受。目前这个问题没有确切的标准。另请参见A.O。 百科:查询字符串

That depends on what the target server accepts. There is no definitive standard for this. See also a.o. Wikipedia: Query string:

虽然目前还没有确切的标准,大多数Web框架允许多个值与单个字段关联(如字段1 =值1&放大器;字段1 =值2和放大器;场2 =值3 [4] [5]

While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. field1=value1&field1=value2&field2=value3).[4][5]

一般情况下,当目标服务器使用的强类型的编程语言如Java( Servlet的 ),那么你可以把他们作为多个参数使用相同的名称。该API通常提供了一个专用的方法来获得多个参数值作为数组。

Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.

foo=value1&foo=value2&foo=value3

String[] foo = request.getParameterValues("foo"); // [value1, value2, value3]

的request.getParameter(富)也将在它的工作,但它会只返回一个值。

The request.getParameter("foo") will also work on it, but it'll return only the first value.

String foo = request.getParameter("foo"); // value1

和,当目标服务器使用的弱类型化语言如PHP或回报率,那么你需要后缀用大括号参数名 [] 为了触发语言返回值而不是单个值的阵列

And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.

foo[]=value1&foo[]=value2&foo[]=value3

$foo = $_GET["foo"]; // [value1, value2, value3]
echo is_array($foo); // true

在情况下,你仍然可以使用富=值1&放大器;富=数值2&放大器;富=值3 ,那么它会只返回第一个值

In case you still use foo=value1&foo=value2&foo=value3, then it'll return only the first value.

$foo = $_GET["foo"]; // value1
echo is_array($foo); // false

请注意,当你发送为foo [] =值1&放大器;为foo [] =值2和放大器;为foo [] =值3 来一个Java Servlet的,那么你仍然可以得到他们,但你需要使用精确的参数名称包括括号。

Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you'd need to use the exact parameter name including the braces.

String[] foo = request.getParameterValues("foo[]"); // [value1, value2, value3]

这篇关于发送阵列与一个HTTP GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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