在GET请求中传递相同参数名称的多个值的正确方法 [英] Correct way to pass multiple values for same parameter name in GET request

查看:1400
本文介绍了在GET请求中传递相同参数名称的多个值的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我看到过这样的网址:

  http:// server / action?id = a& id = b 



我看过这样的网址:

  http:// server / action?id = a,b 

我的理解是,正确,但我找不到任何参考。我查看了http规范,但看不到任何有关如何组成URL的查询部分。



我不想要答案是任何一个都没问题 - 如果我正在构建一个web服务,我想知道哪些方法是标准的,以便使用我的web服务的人知道如何传递多个相同名称的参数。



那么,有人可以指定我的官方参考来源来确认哪个选项是正确的吗?

解决方案

<事实上,没有明确的标准。要支持这些信息,请查看维基百科,在查询字符串一章。有以下评论:

lockquote

虽然没有明确的标准,但大多数web框架允许
多个值与a单个字段。 [3] [4]


此外,当您查看 RFC 3986 ,在 3.4查询部分中,没有具有多个值的参数的定义。

大多数应用程序使用您显示的第一个选项: http:// server / action?id = a& id = b 。要支持这些信息,请查看此 Stackoverflow链接 ,以及有关ASP的 MSDN链接。 NET应用程序,它使用相同的标准来处理具有多个值的参数。



然而,由于您正在开发这些API,我建议您做一些最简单的工作,因为API的调用者在创建查询字符串时不会遇到太多麻烦。


I'm looking into what is the correct way to pass multiple values for the same parameter name in a GET request.

I've seen URLs like this:

http://server/action?id=a&id=b

And I've seen URLs like this:

http://server/action?id=a,b

My understanding is that the first is correct, but I can't find any reference for this. I had a look at the http spec but couldn't see anything about how the 'query' part of a URL should be made up.

I don't want an answer that says "either is fine" - if I'm building a webservice, I want to know which of these methods is standard so that people using my webservice know how to pass multiple parameters for the same name.

So, can someone point me at an official reference source to confirm which option is correct?

解决方案

Indeed, there is no defined standard. To support that information, have a look at wikipedia, in the Query String chapter. There is the following comment:

While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field.[3][4]

Furthermore, when you take a look at the RFC 3986, in section 3.4 Query, there is no definition for parameters with multiple values.

Most applications use the first option you have shown: http://server/action?id=a&id=b. To support that information, take a look at this Stackoverflow link, and this MSDN link regarding ASP.NET applications, which use the same standard for parameters with multiple values.

However, since you are developing the APIs, I suggest you to do what is the easiest for you, since the caller of the API will not have much trouble creating the query string.

这篇关于在GET请求中传递相同参数名称的多个值的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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