-
Notifications
You must be signed in to change notification settings - Fork 272
Post
chrissie1 edited this page Dec 26, 2012
·
3 revisions
According to W3 the post method does the following
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources; - Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles; - Providing a block of data, such as the result of submitting a form, to a data-handling process; - Extending a database through an append operation.
You can post to a service using the post method and using static, anonymous or dynamic objects.
Lets take our Tree as an example.
Our tree object looks like this.
public class Tree
{
public int Id { get; set ; }
public string Genus { get; set; }
}
Now we can post an object to our service like this.
var tree = new Tree();
tree.Id = 1;
tree.Genus = "Fagus";
var http = new HttpClient();
http.Post("url", tree, HttpContentTypes.ApplicationJson);
Or we can do it with an anonymous object like this.
var http = new HttpClient();
http.Post("url", new{Id=1, Genus="Fagus"}, HttpContentTypes.ApplicationJson);
or you can Post a dynamic type.
var tree = new ExpandoObject();
tree.Id = 1;
tree.Genus = "Fagus";
var http = new HttpClient();
http.Post("url", tree, HttpContentTypes.ApplicationJson);
You can choose the contenttype.