ich den OData-Service haben, um eine PUT wir den Header mit If-Match: *
im Posten Mann, den ich wie unten geben und es funktioniertEinstellen der If-Match im Header C#
Wie kann ich dieses If-Match in dem OData-Service-Aufruf 501:Not Implemented
private async Task<HttpResponseMessage> PutJsonAsync(string messageBody,string B_Code)
{
string userName = ConfigurationManager.AppSettings["Username"];
string password = ConfigurationManager.AppSettings["Password"];
string BaseURL = ConfigurationManager.AppSettings["BaseURL"];
try
{
using (var httpClient = new HttpClient())
{
var request = new StringContent(messageBody, Encoding.UTF8, "application/json");
string apiUrl = "SAM('" + B_Code + "')";
request.Headers.ContentType = new MediaTypeHeaderValue("application/json");
request.Headers.TryAddWithoutValidation("If-Match", "*");
var url = string.Format("{0}{1}", BaseURL, apiUrl);
var creds = userName + ":" + password;
var credentials = Encoding.ASCII.GetBytes(creds);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
response = await httpClient.PutAsync(new Uri(url), request);
}
}
catch (Exception ex)
{
throw ex;
}
return response;
}
Aber es und wirft Fehler nicht funktioniert ein PUT operation.I versucht auszuführen gesetzt
`Antwort {Statuscode: 501, ReasonPhrase: 'Nicht implementiert', Version: 1.1, Inhalt: System.Net.Http.StreamContent, Sockel:
OData-Version: 4.0 Datum: Mo, 30. Oktober 2017 20 : 42: 28 GMT Set-Cookie: JSESSIONID = XYZ; Pfad = /; Sichern; Httponly Set-Cookie: XYZ; path = /; SICHERE; Httponly Server: Apache-Coyote/1.1 Vary: Accept-Encoding Verbindung: Keep-Alive- Content-Length: 277 Content-Type: application/json; odata.metadata = minimal }} System.Net.Http.HttpResponseMessage`
@John aktualisiert meine Frage – xyz
Sind Sie den Inhaltstyp auf Ihren Content-Objekt einstellen? Ich bin mir nicht sicher, ob Sie es auf die Anforderungsheader setzen sollen. – john
@John Ich folgte der Antwort für die Frage hier https://StackOverflow.com/Questions/31437925/How-Cani-i-Include-If-None-Match-Header-in-HTTPrequestmessage – xyz