如何在http标头中传递数组? [英] How to pass an array within a http header?

查看:197
本文介绍了如何在http标头中传递数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过http标头传递一个数组。

I would like to pass an array through a http header.

为多个params命名相同的名称是否可以接受,这样我会知道它们属于一个数组,就像在get请求查询字符串中一样?示例:

Would it be acceptable to name multiple params the same name, and that way I would know that they belong to an array just like in a get request query string? Example:

CurrentHeaderArray: myarray[]=value1&myarray[]=value2&myarray[]=value3

已经有一个stackoverflow应答将其传递给get请求的查询字符串,请参阅此超链接。
如何在查询字符串中传递数组?

There is already a stackoverflow answer to pass it through the query string of a get request, see this hyper link. How to pass an array within a query string?

推荐答案

您可以将数组作为字符串传递,并使用一些分隔符char作为csv文件的方式。然后,在服务器端代码中,只需使用一些字符串拆分函数来获取数组。
如果字符串包含分隔符,则转义它们。

You can pass an array as string with some delimiter char as the way csv file does. Then, in the server side code, just use some string split function to get back the array. If the string contains the delimiter charater, escapes them.

这篇关于如何在http标头中传递数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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