Sharepoint Rest OData Api返回一个奇怪的错误

时间:2017-06-07 07:17:34

标签: c# sharepoint odata

我正在使用Sharepoint 2013的OData Rest Api来获取和发布我的.Net应用程序中的数据。 get工作正常,但帖子却给我一个错误。我在小提琴手中看到了这一点:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code>-1, Microsoft.Data.OData.ODataException</m:code>
  <m:message xml:lang="de-DE">Im MIME-Typ fehlt ein Parametername für eine Parameterdefinition.</m:message>
</m:error>

错误消息是德语,但它表示“Mime-Type缺少参数定义的参数名称”

我的发送标题是

POST https://myurl/_api/web/lists(guid'7ED022C7-053F-4057-A141-929DE8AA87A6')/items(3) HTTP/1.1
Accept: application/json;odata=verbose;
X-RequestDigest: 0x0FE934F7228D5D88530162E3E5139D096D2E58E08530600CDF1220B43F7A88B0A4EDE904F5572F4537AFC8383D5FDCD1EA324BF9C3D8F66F9438D58192FA2A85,07 Jun 2017 07:08:45 -0000
Accept-Charset: utf-8
X-HTTP-Method: MERGE
If-Match: *
Content-Type: application/json;odata=verbose;charset=utf-8
Host: intranet.weisseskreuz.bz.it
Content-Length: 54
Expect: 100-continue

{"__metadata":{"type":"SP.ListItem"},"TitleDE":"dddd"}

我使用此代码发送帖子

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(internalUrl);
            request.Accept = "application/json;odata=verbose;";            
            request.Headers.Add("X-RequestDigest", GetFormDigest(baseUrl, credential, cookie));
            request.ContentLength=json.Length;
            request.Headers.Add("Accept-Charset", "utf-8");
            request.Method = "POST";
            request.Headers.Add("X-HTTP-Method", "MERGE");
            request.Headers.Add("If-Match", "*");
            request.ContentType = "application/json;odata=verbose;charset=utf-8";          
            CredentialCache credentialCache = new CredentialCache();
            credentialCache.Add(new Uri(internalUrl), "NTLM", credential);
            request.Credentials = credentialCache;

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            HttpWebResponse responseInternal = (HttpWebResponse)request.GetResponse();

感谢您的帮助,我有点绝望。

1 个答案:

答案 0 :(得分:1)

我刚刚解决了此类错误。删除了accept标头中不必要的分号。

上一个:

application/json;odata=verbose;

application/json;odata=verbose