Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft.Data.OData.ODataContentTypeException:找不到与响应的内容类型匹配的受支持MIME类型_C#_.net_Sharepoint_Rest_Odata - Fatal编程技术网

C# Microsoft.Data.OData.ODataContentTypeException:找不到与响应的内容类型匹配的受支持MIME类型

C# Microsoft.Data.OData.ODataContentTypeException:找不到与响应的内容类型匹配的受支持MIME类型,c#,.net,sharepoint,rest,odata,C#,.net,Sharepoint,Rest,Odata,我遇到了以下异常 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

我遇到了以下异常

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“错误请求”。我找不到任何头值,这些头值将强制此代码使用允许的内容类型。在某些情况下,当我在Accept头中设置一些总垃圾时,我得到了406个完全符合文档要求的“不可接受”

根据这个odata文档,我还试图将查询字符串设置为
$format=JSON
$format=atom
,但我从未注意到这个参数有任何不同(似乎被忽略了)

所以我的问题是-我缺少什么


WinRT应用程序调用SharePoint 2013 OData服务(_api/web/lists/)时使用了该代码,但我认为(并希望)问题并没有那么具体。

您能否尝试捕获HTTP跟踪(Fiddler肯定可以做到这一点)。从代码上看,它看起来不错,但重要的是线路上的内容。