0
 string cont = "{ '__metadata': { 'type': 'SP.Data.IssuesListItem' }, 'Status': 'Close'}";
 var content = new StringContent(cont, Encoding.UTF8, "application/json");
 string url = "https://mywebsite.com/_api/web/lists/GetByTitle('tasks')/items?$filter=ID eq 932"
    
 var credential = new System.Net.NetworkCredential(
                 "username",
                 "password",
                 "domain");
    
 using (var handler = new HttpClientHandler() { Credentials = credential, UseProxy = false })
    {
        using (var client = new HttpClient(handler))
            {
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Add("X-HTTP-Method", "MERGE");
              var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
              mediaType.Parameters.Add(new NameValueHeaderValue("odata", "nometadata"));
              client.DefaultRequestHeaders.Accept.Add(mediaType);
              client.DefaultRequestHeaders.Add("X-RequestDigest", await GetRequestDigest());
              client.DefaultRequestHeaders.Add("binaryStringRequestBody", "true");
              client.DefaultRequestHeaders.Add("IF-MATCH", "*");
              HttpResponseMessage response = await client.PostAsync(url, content);
              response.EnsureSuccessStatusCode();
              }
     }

in this code I'm trying to change the status of an issue list to "Close", the GetRequestDigest() Method is working well but I'm receiving Bad Request in the response when i reach PostAsync(url,content). Any help please Thanks in advance...

someone
  • 139
  • 1
  • 12
  • Your URL's `filter` query parameter contains spaces - those may need to be [encoded properly](https://stackoverflow.com/questions/575440/url-encoding-using-c-sharp). – Timothy G. May 05 '21 at 14:34
  • @TimothyG. this URL works well in the Get Method when reading the item from the list – someone May 05 '21 at 14:37

0 Answers0