c# - 有效负载中的属性文件夹的值与架构 Graph Api 不匹配
问题描述
在一个驱动器中创建文件夹的图形 API 请求是
POST /me/drive/root/children
Content-Type: application/json
{
"name": "New Folder",
"folder": { },
"@microsoft.graph.conflictBehavior": "rename"
}
这但我不明白如何在 httprequest 内容正文中传递“{}”。
我的代码:
var tt = "{ }";
var jsonData = $@"{{ ""name"": ""{txtValue}"",""folder"":""{tt}""}}";
var body = new StringContent(jsonData, Encoding.UTF8,
"application/json");
apiRequest.Content = body;
apiRequest.Headers.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await httpClient.SendAsync(apiRequest);
string d = response.Content.ReadAsStringAsync().Result.ToString();
但给出错误 ""code": "BadRequest","message": "payload 中的属性文件夹的值与架构不匹配。","
有人可以帮帮我吗?
解决方案
有什么特别的理由不使用Microsoft Graph Client Library for .NET
这件事吗?
无论如何,以下示例演示了如何通过以下方式在驱动器中 创建新文件夹HttpClient
:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
client.BaseAddress = new Uri("https://graph.microsoft.com");
var folderPayload = new Dictionary<string, object>
{
["name"] = "Test Folder",
["folder"] = new { },
["@microsoft.graph.conflictBehavior"] = "rename"
};
var requestContent = new StringContent(JsonConvert.SerializeObject(folderPayload));
requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await client.PostAsync($"/v1.0/me/drive/root/children", requestContent);
var data = response.Content.ReadAsStringAsync().Result.ToString();
}
推荐阅读
- python - 为什么当需要 str 和 float 时 bool 和 int 不被视为类型错误?
- qml - 为什么 QML 变量不能大写?
- node.js - 使用 Google Cloud SDK shell 在 GAE 中部署
- bash - 对出现的行数进行排序和计数
- c - 错误:参数为
在 C 中初始化 - typo3 - 打字稿获取页面的uid
- azure - 无法连接到 Azure VM
- c++ - 如何修复 Visual Studio 2017 中的“命名空间 std 没有成员 scoped_lock”错误
- java - Java ConcurrentHashSet - 在多线程环境中对其进行迭代
- amazon-web-services - AWS DMS 复制实例内存不足