I am using http party gem to try and send some json to a web api I have running in Visual Studio.
The C# implementation of my Post API is as below:
public string GetInfo([FromBody]MyClass[] postedValues)
{
//do stuff
If I configure fiddler to hit the method and within fiddler set the request header to be:
Content-Type: application/json; charset=utf-8
and then the request body to be:
[{"Id" : "1", "A" : "1", "B" : "1", "c" : "1"}, {"Id" : "2", "A" : "2", "B" : "2", "C" : "2"}]
when I hit execute the postedValues
automatically maps the values from the json into the array - so for the above there will be 2 elements in the array - the Id
in MyClass postedValues[0]
will be 1
and the Id
in postedValues[1]
will be 2
and the same for all the other properties.
I want to hit the WebAPi from Ruby on Rails so I am using http party and building the request as below(note full http:// taken out of URL):
post('localhost/api/MyController/GetInfo', :body => [{:Id => '1',
:A => '1',
:B => '1',
:C => '1'}].to_json,
:headers => {'Content-Type' => 'application/json'})
However now if I put a breakpoint in my C# method postedValues
is null. If I change the C# method to:
public string GetInfo([FromBody]dynamic postedValues)
{
//do stuff
and run the Ruby code I do see values passed but would much prefer if the values were mapped automatically as they are when I hit it from Fiddler - is there something I am doing incorrect with http party?