I got an Service to Post Data and Returning Location of Created Object
public IHttpActionResult Post([FromBody]ErbrachteLeistung value)
{
int newLeistungId = service.AddErbrachteLeistung(value);
return Created($"api/ErbrachteLeistung/{newLeistungId}", value);
}
My Client Looks like this
HttpClientHandler handler = new HttpClientHandler
{
UseDefaultCredentials = true,
AllowAutoRedirect = true
};
using (HttpClient client = new HttpClient(handler))
{
client.BaseAddress = new Uri(WebApiUri);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.PostAsJsonAsync<ErbrachteLeistung>("api/ErbrachteLeistung", erbrachteLeistung).Result;
response.EnsureSuccessStatusCode();
}
How can I read the Created Location given in the WebService out of the Response?