I am using PowerShell V4, with the Invoke-RestMethod
command:
Add-Type @"
using System;
public class Person{
public Guid Id {get;set;}
public string Name {get;set;}
public int Age {get;set;}
}
"@
$person = New-Object Person
$person.Age = [int]::(Get-Random -Maximum 99 -Minimum 20)
$person.Name = [string]::("Test" + (Get-Random -Minimum 10 -Maximum 100))
Invoke-RestMethod -Uri "http://localhost:51624/api/personapi" -Method Post -Body $person
In the server side,
[HttpPost]
public IHttpActionResult Post(Person person)
{
...
return Ok();
}
The person
object received in server side is all properties default, for instance the Age
is 0
and Name
is null
. If I change $person
to @{Name="..."; Age=11}
then it's ok.
Did I miss something, I want to hold the class definition?