Creating an entry using Simple.OData.Client
I need to use the method InsertEntryAsync()
. Correct?
The body of the oData
request contains the insert data in Json format, but where do I have to set the body for such a call?
My coding looks like this:
using Simple.OData.Client;
var client = new ODataClient(
new ODataClientSettings
{
BaseUri = baseUri,
Credentials = credentials,
OnTrace = OnTraceHandler,
});
var headers = new Dictionary<string, IEnumerable<string>>
{
{ "Accept-Language", new string[] { "de-DE" } },
{ "Accept", new string[] { "application/json" } },
{ "X-CSRF-TOKEN", new string[] { Class1.x_scrf_token } }
};
client.UpdateRequestHeaders(headers);
var dict = new Dictionary<string, object>();
string body = "{\"name\":\"John\", \"city\":\"New York\"}";
var entryInsert = await client.InsertEntryAsync("PeopleSet", dict);
Found the solution myself. Instead of attaching a Json as body, I need to set the values to the dictionary like
dict.Add("name", "John"); dict.Add("city", "New York");
and use the dict as second parameter of InsertEntryAsync("PeopleSet", dict).