36

I want to send array using postman. the request looks like this: enter image description here

Im using postman to execute requests. I found on the internet to send array via form-data or raw. But I need them to be send as x-www-form-urlencoded. I tried it this way: enter image description here

But its wrong because value ads is string not array.

Haniku
  • 671
  • 1
  • 7
  • 16
  • You can use the above style but just remove `[]` from the value like `1,2,3` from `[1,2,3]` I have done it, It was working fine!! – KNDheeraj Jan 14 '19 at 13:14
  • This basically works as `1,2,3.split(',')` so it will give `1` `2` `3` but if your sending "abc,@mail.com","de,f@mail.com" then it would give `abc` `@mail.com` `de` `f@mail.com`. If this is not what your looking then you must have to follow write it in below style where we repeat same key – KNDheeraj Jan 14 '19 at 13:23

9 Answers9

31

I had a bit of a more complex objects. A class emaillist

public class emailist
{
    public String id { get; set; }
    public String emailaddress { get; set; }
    public String name { get; set; }
}   

A class emailRecipientList

public class emailRecipientList
{
    public String procedure { get; set; }
    public String server { get; set; }
    public String filename { get; set; }
    public String fileid { get; set; }
    public List<emailist> emaillists { get; set; }

}

And a Task

public async Task<System.Xml.XmlElement> postUploadEmailRecipientList([FromBody] emailRecipientList recipientList)

Now to send the data as "application/x-www-form-urlencoded" enter image description here

If more elements need to get added just keep increasing the array index. I tested it on a asp.net WebAPI 2 project and worked fine.

El Bayames
  • 545
  • 7
  • 14
  • 7
    This should be the best answer as this actually solves the question the the author had originally. – Darktega Apr 25 '19 at 00:52
  • unfortunately, the emaillists[Index][id] doesn't work for me , when I check postman body request it shows "emaillists[Index][id] " = "115" do you've any Idea why ? – Emad Jan 11 '21 at 10:52
  • This is the only answer that works for complex objects. Thank you so much. – Saurabh Padwekar Mar 06 '23 at 06:40
18

If you want to pass 1,2,3 in array ads , try with below screenshot

enter image description here

Ikbel
  • 7,721
  • 3
  • 34
  • 45
9

Just figured out how it's done, same as in html forms

cheers

enter image description here

Magus
  • 2,905
  • 28
  • 36
7

I wasnt able to solve it via x-www-form-urlencoded even I found solutions like ads[].id, ads[0].id, ads.id,... It wasnt working. So I had to write it as raw. and in headers section change it this way. enter image description here

And the body is:

{ "deleted": "false",
  "ads": 
  [
    {
      "id": 15
    },
    {
      "id": 20
    }
  ]
}
Haniku
  • 671
  • 1
  • 7
  • 16
5

Just Use the key without square brackets

enter image description here

Lalit Kumar
  • 107
  • 1
  • 4
2

check this image

as part of x-www-form-urlencoded

i think you can just repeat the same key and give it different value id for example

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23
0

For adding array as value, click Bulk Edit in body tab of postman.

It will allow you to input of key value pairs in blank area.

Enter the data of key value pair as below:

Id:1

FirstName:John

LastName:Smith

For adding bytes of Image in ImageData key array generate the byte array of image and enter or copy/paste as below:

Id:1

FirstName:John

LastName:Smith

ImageData:255

ImageData:216

ImageData:255

...

...

This will send the data in array for key ImageData.

Employee
  • 3,109
  • 5
  • 31
  • 50
0

Try the below screenshot:

enter image description here

My postman version is 7.13.0.

Sajjad Alipour
  • 184
  • 1
  • 6
0

you need to send data params separately:

--data 'some[0]=123'
--data 'some[1]=345'

or:

--data 'some[0][key1]=123'
--data 'some[0][key2]=345'

its will be work