¿Es posible enviar una matriz con la extensión Postman Chrome?


He estado usando Postman Chrome extensión para probar mi API y me gustaría enviar una matriz de IDs a través de post. ¿Hay alguna manera de enviar algo listar esto como un parámetro en Postman?

{
  user_ids: ["1234", "5678"]
}
Author: rsanchez, 2012-10-06

15 answers

Necesitas sufijar el nombre de tu variable con [] así:

send_array_param_with_postman

Si eso no funciona, intente no poner los índices entre paréntesis:

my_array[]  value1
my_array[]  value2

Nota:

  • Si está utilizando la aplicación empaquetada postman , puede enviar una matriz seleccionando raw / json (en lugar de form-data). Además, asegúrese de establecer Content-Type como application/json en la pestaña Headers. Aquí hay un ejemplo para datos en bruto {"user_ids": ["123" "233"]}, ¡no olvide las comillas!

  • Si está utilizando el cliente REST postman tiene que usar el método que describí anteriormente porque pasar datos como raw (json) no funcionará. Hay un error en el cliente REST de postman (Al menos obtengo el error cuando uso 0.8.4.6).

 317
Author: Benjamin Crouzier,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-09 01:29:21

Para mí no trabajar con array[0], array1, .. o array[], array[], ... . Funciona de forma más sencilla: introduzca la descripción de la imagen aquí

 43
Author: Popa Andrei,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-17 21:03:38

Aquí está mi solución:

Use form-data y edite como se muestra a continuación:

Key       Value 
box[]      a
box[n1]    b
box[n2][]  c
box[n2][]  d

Y obtendrás una matriz como esta:

{"box":{"0":"a","n1":"b","n2":["c","d"]}}
 33
Author: Nutto,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-03 03:09:50

También tuve ese problema, y lo resolví haciendo lo siguiente:

1-Ir a la configuración del encabezado de la solicitud y agregar lo siguiente:

Accept : application/json, text/plain, */*
Content-Type : application/json;charset=UTF-8

2-Para enviar el array json, me pongo en formato json crudo y establezco el array:

["bbbbbbbbbb","aaaaaaaaaa","987654321","123456789"]
 20
Author: mesteves,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-29 09:17:38

Como lo mencionó @pinouchon, puede pasarlo con la ayuda de array index

my_array[0] value
my_array[1] value

In addition to this, to pass list of hashes, you can follow something like:

my_array[0][key1] value1

my_array[0][key2] value2

Ejemplo:

To pass param1=[{name:test_name, value:test_value}, {...}]

param1[0][name] test_name

param1[0][value] test_value
 14
Author: Manoj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-04 18:23:08

Establecer el cuerpo como raw y formar la matriz de la siguiente manera:

introduzca la descripción de la imagen aquí

 9
Author: danywarner,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-04 22:54:16

En los encabezados set

content-type : application/x-www-form-urlencoded

En el cuerpo seleccione la opción

X-www-form-urlencoded

E insertar datos como matriz json

user_ids : ["1234", "5678"]
 5
Author: Aris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-04 14:37:21

Esto funcionó para mí. para pasar una matriz de Item object {ItemId, ColorID,SizeID, Quntity}

Datos del cartero

 5
Author: Abdu Imam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-30 14:33:31

Elija form-data o urlencoded y use la misma clave "user_ids". El servidor debe recibirlo como una matriz.

 4
Author: Abhinav,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-06 20:21:42
{
    "data" : [  
        {
            "key1" : "value1",
            "key2" : "value2"   
        },
        {
            "key01" : "value01",
            "key02" : "value02"             
        },
        {
            "key10" : "value10",
            "key20" : "value20"   
        }
    ]
}

Puedes pasar así. Espero que esto ayude a alguien.

 2
Author: Narendra Solanki,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-13 13:12:27

Esto también funciona para las listas dentro del objeto:

Id:37
IdParent:26
Name:Poplet
Values[0].Id:1349
Values[0].Name:SomeName
Values[1].Id:1350
Values[1].Name:AnotherName

El JSON equivalente sería:

{
    "Id": 37,
    "IdParent": 26,
    "Name": "Poplet",
    "Values": [
        {
            "Id": 1349,
            "Nombre": "SomeName"
        },
        {
            "Id": 1350,
            "Nombre": "AnotherName"
        }
    ]
}
 1
Author: onicofago,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-25 12:06:35

Probé todas las soluciones aquí y en otros posts, pero nada ayudó.

La única respuesta me ayudó:
Adición del atributo [FromBody] antes de la decleración del parámetro en la firma de la función:

[Route("MyFunc")]        
public string MyFunc([FromBody] string[] obj)
 0
Author: Ariela,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-09 09:16:01

En forma-datos,

   key              value

 user_ids[]         1234
 user_ids[]         5678
 0
Author: Mritunjay Upadhyay,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-16 10:25:43

Es importante saber que el campo valor solo puede contener un valor (sin especificadores).

Si desea enviar, por ejemplo, una matriz de "mensajes" con Postman, cada uno con una lista de pares clave/valor, ingrese, por ejemplo, messages [] [reason] como clave y el valor de reason en value:

introduzca la descripción de la imagen aquí

El servidor recibirá:

{"messages"=>[{"reason"=>"scrolled", "tabid"=>"2"}, {"reason"=>"reload", "tabid"=>"1"}], "endpoint"=>{}}
 0
Author: Alexander Roehnisch,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-07 08:15:09

Si desea una matriz de dictados, pruebe esto: introduzca la descripción de la imagen aquí

 0
Author: C.K.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-17 11:04:44