Home  >  Article  >  Backend Development  >  Http中请求参数是数组的情况下,什么时候需要在参数名上加方括号[]?

Http中请求参数是数组的情况下,什么时候需要在参数名上加方括号[]?

WBOY
WBOYOriginal
2016-06-06 20:12:501467browse

Android(Retrofit) 请求code

<code>@FormUrlEncoded
@POST("util/pinyin")
Call<apiresponse>> pinyin(@Field("lrcs[]") String[] lrcs);
</apiresponse></code>

比如这样就可以得到正确的请求结果,而用 '@Field("lrcs")' 服务端就只能收到我发出去的数组的最后一个元素。
我自己抓包看 确认是全部包含在post body里发出去了。

这是服务端解析框架的限制?还是HTTP协议的要求?还是FormUrlEncoded的限制?

用 方括号(square brackets) + Http / POST 做关键词没有找到什么有关联的结果。

回复内容:

Android(Retrofit) 请求code

<code>@FormUrlEncoded
@POST("util/pinyin")
Call<apiresponse>> pinyin(@Field("lrcs[]") String[] lrcs);
</apiresponse></code>

比如这样就可以得到正确的请求结果,而用 '@Field("lrcs")' 服务端就只能收到我发出去的数组的最后一个元素。
我自己抓包看 确认是全部包含在post body里发出去了。

这是服务端解析框架的限制?还是HTTP协议的要求?还是FormUrlEncoded的限制?

用 方括号(square brackets) + Http / POST 做关键词没有找到什么有关联的结果。

http协议的要求

解析参数时,相同的key会覆盖前一个,
如果带[]会当成一维数组来处理,就不会覆盖了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn