0

In my code i send a post to rest service such as:

var response = await client.PostAsJsonAsync(requesturi, mydata);

mydata collection is translated to Json by PostAsJsonAsyn as:

{
    "queryid" : "GetNames",
    "@StartDate" : "1/1/2019",
    "@EndDate" : " "2/1/2019"
}

However the server return Http 400 reponse unless the jason object is wrapped in brackets (tested in Postman)

[
   {
       "queryid" : "GetNames",
       "@StartDate" : "1/1/2019",
       "@EndDate" : " "2/1/2019"
   }
]

Is there any way to add the brackets to json object passed by PostAsJasonAsyn method

Thanks

Arian
  • 12,793
  • 66
  • 176
  • 300
John Sheridan
  • 83
  • 1
  • 2
  • 10
  • Brackets indicate array, so it seems that is expected. You will have to create mydata to be a list/array/enumerable. Can you show us what mydata is? – CrnaStena Jan 23 '19 at 21:04

2 Answers2

1

Try this:

var response = await client.PostAsJsonAsync(requesturi, new[] { mydata } );
AlbertK
  • 11,841
  • 5
  • 40
  • 36
-1

That's becuase standard of JSON. you should search on the internet first:

https://jsonlint.com/

How do I turn a C# object into a JSON string in .NET?

Working With JSON in C#

Arian
  • 12,793
  • 66
  • 176
  • 300