-
-
Save NDiiong/f8750792b4a1c2986c1c7d4a16ef0e04 to your computer and use it in GitHub Desktop.
HttpClient Sample2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.DefaultRequestHeaders.Accept.Clear(); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
var param = new Dictionary<string, string> | |
{ | |
{ | |
"title", title | |
} | |
}; | |
var query = await new FormUrlEncodedContent(param).ReadAsStringAsync(); | |
var response = await Client.GetAsync($"https://api/Function1?{query}"); | |
if (!response.IsSuccessStatusCode) | |
{ | |
// TODO エラー処理? | |
return; | |
} | |
var json = await response.Content.ReadAsStringAsync(); | |
var res = JsonConvert.DeserializeObject<SearchMovieResponse>(json); | |
res.Results.ForEach(item => | |
{ | |
// TODO 画像のパス作成をどこでする? | |
_movies.Add(new MovieItem(item.Id, item.Title, item.PosterPath)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment