2017-06-06 1 views
1

でASPNET WEBAPIから作成されたオブジェクトの場所を取得、私は私のクライアントは、私は読むことができますどのようにこのはHttpClientを

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

のように見えるポストデータや作成されたオブジェクト

public IHttpActionResult Post([FromBody]ErbrachteLeistung value) 
{ 
    int newLeistungId = service.AddErbrachteLeistung(value); 
    return Created($"api/ErbrachteLeistung/{newLeistungId}", value); 
} 

の戻る場所にサービスを得ましたレスポンスのWebServiceに与えられた作成された場所? Locationヘッダの値

答えて

0

201作成した応答を格納

//... 
response.EnsureSuccessStatusCode(); 
Uri location = response.Headers.Location; 

//...