[英]How to set the body for a Simple.OData.Client create entry request using C#?
使用Simple.OData.Client
創建條目我需要使用方法InsertEntryAsync()
。 正確?
oData
請求的主體包含Json格式的插入數據,但是我必須在哪里設置此類調用的主體?
我的編碼如下:
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);
自己找到解決方案。 無需將Json附加為主體,我需要將值設置為字典,例如
dict.Add(“ name”,“ John”); dict.Add(“ city”,“紐約”);
並將dict用作InsertEntryAsync(“ PeopleSet”,dict)的第二個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.