3

我收到以下异常

Microsoft.Data.OData.ODataContentTypeException: 
A supported MIME type could not be found that matches the content 
type of the response. None of the supported type(s) 
'application/atom+xml;type=entry, application/atom+xml, application/json;odata=verbose' 
matches the content type 'application/json'.
     at Microsoft.Data.OData.MediaTypeUtils.GetFormatFromContentType....

使用代码

var someJason = "{'__metadata':{'type':'SP.Data.TestObjectItem'}, " + jsonProperties + "}";
var content = new ByteArrayContent(Encoding.UTF8.GetBytes(someJason));
content.Headers.Add("X-RequestDigest", formDigest);

var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, queryUrl);
httpRequestMessage.Content = content;
httpRequestMessage.Headers.Add(HttpRequestHeader.Accept.ToString(),
                               "application/json;odata=verbose");
httpRequestMessage.Headers.Add(HttpRequestHeader.ContentType.ToString(),
                               "application/json;odata=verbose");
var result = await client.SendAsync(httpRequestMessage);

result变量总是返回 400 'Bad Request'。我找不到任何会强制此代码使用允许的内容类型的标头值。在某些情况下,当我在 Accept 标头中设置一些完全垃圾时,我会得到 406 'Not Acceptable',它完全符合 http://www.odata.org/documentation/operations文档。

根据这个 odata 文档,我试图将查询字符串也设置为$format=JSONand $format=atom,但我从来没有注意到这个参数有任何区别(似乎它被忽略了)。

所以我的问题是 - 我错过了什么?

代码用于调用 SharePoint 2013 OData 服务 (_api/web/lists/) 的 WinRT 应用程序,但我认为(并希望)问题不是那么具体。

4

0 回答 0