How to pass an array within a http header?

不羁的心 提交于 2020-01-06 04:00:06

问题


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

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

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?


回答1:


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.




回答2:


You can pass an array as a header like this:

CurrentHeaderArray : [ "value1", "value2", "value3" ]

You can easily try this in a tool like Fiddler, using the Composer.



来源:https://stackoverflow.com/questions/29139035/how-to-pass-an-array-within-a-http-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!