1
votes

I am using the OData Rest Api of Sharepoint 2013 to get and post data in my .Net application. The get works fine but the post throws me a an error. I see this in my fiddler:

<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>

The error message is in german but it means "The Mime-Type is missing a parameter name for a parameter definition"

My send headers are this

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"}

I use this code to send my post

            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();

Thanks for help I am a little bit desperate.

1
"ContentLength: 54" Typo? it's "content-length"Marvin Smit
@MarvinSmit ok this was an error. changed to the right code (see above) but the error remains the same. Thanks for your hintcpiock
OData version related? Accept header => msdn.microsoft.com/en-us/library/dd541269.aspxMarvin Smit
you save my live!!! Thx. It was the accept header which is to set to application/json. Can you add this as answercpiock

1 Answers

1
votes

I've just resolved this type of error. Removed an unnecessary semicolon in the accept header.

Previous:

application/json;odata=verbose;

New:

application/json;odata=verbose