Microsoft Graph API 一个驱动器无法读取 JSON 请求负载

Microsoft Graph API One Drive Unable to read JSON request payload

当我发出 PUT API CALL 以使用 Microsoft Graph API 将文档上传到 OneDrive 时收到以下错误。之前一直在工作,突然停止工作了。

{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n
\"message\": \"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.\",\r\n \"innerError\": {\r\n \"request-id\": \"133ac360-740d-4823-9a93-1090616d925b\",\r\n \"date\": \"2016-04-11T06:24:59\"\r\n }\r\n }\r\n}

我正在执行的代码是

 using (var client = new HttpClient())
            {
                string url = https://graph.microsoft.com/v1.0/me/drive/root:/Test.xslx:/content
                using (var request = new HttpRequestMessage(HttpMethod.Put, url))
                {
                    string headerAcceptTest = "application/json";
                    MediaTypeWithQualityHeaderValue headerAccept = new MediaTypeWithQualityHeaderValue(headerAcceptTest);
                    request.Headers.Accept.Add(headerAccept);
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    request.Content = new ByteArrayContent(data);
                    request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

                    using (var response = await client.SendAsync(request))
                    {
                        if (response.StatusCode == HttpStatusCode.Created)
                        {
                            string responseContentAsString = await response.Content.ReadAsStringAsync();

                        }
                    }
                }
            }

知道我哪里出错了吗?

我看到 One Drive API 在将文件上传到 One Drive 时的行为发生了变化。( https://dev.onedrive.com/items/upload_put.htm),此 API 调用失败并出现错误。

样品请求:

放置https://graph.microsoft.com/v1.0/me/drive/items/root/children/732f64cc-0719-4a24-abe8-6fd39cb96403.txt/content?%40name.conflictBehavior=replace

回应

{ "error":{ "code": "BadRequest", "message": "Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.", "innerError":{ "request-id": "7e734f93-3033-4bb4-a433-c5d9c400f46e", "date":“2016-04-11T02:33:35” } } }

实际上它在 2016 年 4 月 8 日之前都运行良好,文档说明了它的 text/plain 内容类型,为什么要这样 application/json

周末推出的新版本存在问题,我们现在已将其恢复。现在应该解决该问题。