Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

C# Json POSt to Rest API

I need to post to a rest api and get back the response using the following...
Please create a POST (Not your GET example)  request using the Endpoint: http://myurl.com:9000/eventEW/create
Authentication
Username: muusername
Password: 1d491bca894e
Response format: JSON
Body Parameters (JSON Format):
Request example:

{
 "code":null,
"description":"Event123 Day Trip",
"address":null,
"dateEvent", "2016-12-31",
"type": "DayTrip"
}
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Larry Brister

ASKER

Perfect
Thanks
HttpClient would be the preferred way to approach this. That class is set up to work asynchronously by default. (As developers, we desire asynchronicity in most of our code dealing I/O requests, such as web requests.) If you also add a reference to System.Net.Http.Formatting, then you'll have access to the extension methods defined under the System.Net.Http namespace. These include the PostAsJsonAsync. Then it simply becomes a matter of passing in an object that represents the structure of the JSON you need to send.

Converted by http://json2csharp.com/
public class RootObject
{
    public object code { get; set; }
    public string description { get; set; }
    public object address { get; set; }
    public string dateEvent { get; set; }
    public string type { get; set; }
}

Open in new window

Kaufmed
Do I need to open another question to get an example?